Slurry transfusion#11089

Slurry transfusion

2 seconds
256 megabytes
Hard

The evil Dr. Fufelschmirtz is up to something again. Perry the platypus has already infiltrated his secret lair and found the laboratory where Doofenshmirtz pours slurry. It is not yet very clear why he is doing this, but one thing is clear, he must be stopped!

Heinz has three slurry tanks with volumes n_1, n_2 and n_3 liters filled with slurry at a_1, a_2 and a_3 liters respectively. He wants to ensure that the tanks are filled exactly to b_1, b_2 and b_3 liters, but the order of the tanks is not important. Fufelschmirtz always pours according to the following rules:

- In one transfusion, you can pour liquid from one tank to another. - The pouring continues until the first tank is empty or the second tank is full.

Help Agent P calculate the minimum number of transfusions Heinz needs to make in order to get what he wants.

Input

The first line contains three integers n_1, n_2 and n_3 (1 \leq n_i \leq 10^6) - the tank volumes.

The second line contains three integers a_1, a_2 and a_3 (0 \leq a_i \leq n_i) - the current fluid levels.

The third line contains three integers b_1, b_2 and b_3 (0 \leq b_i \leq 10^6) - the desired ending fluid levels.

Output

Print a single integer - the minimum number of transfusions for which Heinz can get the desired liquid levels in the tanks, or "-1" if this is not possible.

Examples

Example 1

Loading
Loading