Under construction

Still being built. Things may change

Bookshelves

Interview

Time limit1sMemory limit1024 MB

Summary
Given counts of small, medium, and large books and the shelf size, find the fewest shelves needed to hold all books without splitting any book.
Level

Medium5 of 10

Topics
Dynamic programming
Solved
No attempts yet

Problem

You are buying bookshelves to fit all of your books. You already know which books you have and need to work out how many shelves are required. The books come in three sizes: a small book takes 11 space unit, a medium book takes 22, and a large book takes 33. Each shelf holds a fixed number of space units.

Given how many books of each size you have, write a program that computes the fewest shelves needed to fit all of them.

Input

The first line contains three integers: the number of small books, the number of medium books, and the number of large books, in that order. The number of books of each size is at most 2020.

The next line contains an integer SS (S≤20S \le 20), the size of one shelf in space units. At least 22 shelves are always required.

Output

Print the minimum number of shelves needed to fit all the books.

Examples4

  1. Example 1

    Input
    20 0 0
    10
    
    Expected output
    2
    
  2. Example 2

    Input
    0 0 10
    10
    
    Expected output
    4
    
  3. Example 3

    Input
    8 7 5
    15
    
    Expected output
    3
    
  4. Example 4

    Input
    1 4 13
    7
    
    Expected output
    8