eolymp
bolt
Try our new interface for solving problems
Problems

Slurry transfusion

Slurry transfusion

Time limit 2 seconds
Memory limit 256 MiB

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 data

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

Output data

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

Input example #1
10 5 3
7 1 2
3 3 4
Output example #1
2
Source 2020 Cycle of Internet Olympiads for schoolchildren, Third team contest, Novemver 7, Problem B