Fill the Box#1595

Fill the Box

1 second
128 megabytes
Very easy

You are given a box with dimensions length \times width \times height. The box must be completely filled with cubes. The sides of the cubes are powers of two: 1 \times 1 \times 1, 2 \times 2 \times 2, 4 \times 4 \times 4, 8 \times 8 \times 8, For each size of cube 2^i \times 2^i \times 2^i, you are given the number of available cubes.

Find the minimum number of cubes required to completely fill the box, or output -1 if it is impossible.

Input

The input consists of multiple test cases. For each test case, the first line contains length, , (1 \le length, width, height \le 10^6) and (1 \le k \le 20), the number of cube types. The second line contains positive integers not greater than 10^6: the -th number denotes the number of cubes of size 2^i \times 2^i \times 2^i ( from to k-1) that you have.

Output

For each test case, print in a separate line the minimum number of cubes required to completely fill the box, or -1 if it is impossible.

Examples

Example 1

Loading
Loading