cho.sh
Notes
Loading...

Coin Exchange

Time limit

2s

Memory limit

128 MB

Problem

Sejun currently has G1 gold coins, S1 silver coins, and B1 bronze coins. To buy a new laptop, he needs at least G2 gold coins, at least S2 silver coins, and at least B2 bronze coins.

At the bank, each exchange must be one of the following four types.

  1. Exchange 1 gold coin for 9 silver coins.
  2. Exchange 11 silver coins for 1 gold coin.
  3. Exchange 1 silver coin for 9 bronze coins.
  4. Exchange 11 bronze coins for 1 silver coin.

Find the minimum number of exchanges needed so that, after all exchanges, he has at least the required number of each coin.

Input

The first line contains the current numbers of coins, G1 S1 B1.

The second line contains the required numbers of coins, G2 S2 B2.

Every value is an integer between 0 and 1,000,000, inclusive.

Output

Print the minimum number of exchanges needed. If it is impossible to obtain the required numbers of coins, print -1.