There are clocks, arranged in a array. They are labelled:
A B C
D E F
G H I
Each clock is set to either one o'clock, two o'clock, three o'clock, …
or twelve o'clock.
There are nine possible moves, numbered from to . Each move advances
a certain set of clocks by hour. The moves and their corresponding
sets of clocks are:
1 ABDE
2 ABC
3 BCEF
4 ADG
5 BDEFH
6 CFI
7 DEGH
8 GHI
9 EFHI
We wish to know the shortest sequence of moves that will restore all the
clocks to twelve o'clock.
For example, suppose , , and are initially set to eleven o'clock, ,
, and are set to twelve o'clock, and , , and are set to ten
o'clock. Then, doing move once and move twice resets all the
clocks.
Input Specification
lines, containing one integer each, the initial states of clocks , , , , , , , , and , respectively, where denotes one o'clock, denotes two o'clock, and so on.
Output Specification
lines, containing one integer each. Line should contain the number of times to do move in the shortest possible sequence of moves.
Sample Input
11
11
11
12
12
12
10
10
10
Sample Output
0
1
0
0
0
0
0
2
0
Comments