Slurry transfusion
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 Huntz 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 ≤ n[i]
≤ 10^6
) - the tank volumes.The second line contains three integers a[1]
, a[2]
and a[3]
(0 ≤ a[i]
≤ n[i]
) - the current fluid levels.The third line contains three integers b[1]
, b[2]
and b[3]
(0 ≤ b[i]
≤ 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.