#t293. 拨钟问题

拨钟问题

Clock Puzzle

Problem Background

Special for beginners, ^_^

Problem Description

There are 99 clocks arranged in a 3×33 \times 3 matrix:

|-------|    |-------|    |-------|
|       |    |       |    |   |   |
|---O   |    |---O   |    |   O   |
|       |    |       |    |       |
|-------|    |-------|    |-------|
    A            B            C

|-------|    |-------|    |-------|
|       |    |       |    |       |
|   O   |    |   O   |    |   O   |
|   |   |    |   |   |    |   |   |
|-------|    |-------|    |-------|
    D            E            F

|-------|    |-------|    |-------|
|       |    |       |    |       |
|   O   |    |   O---|    |   O   |
|   |   |    |       |    |   |   |
|-------|    |-------|    |-------|
    G            H            I

Now we want to use the minimum number of moves to set all 99 clock hands to the 1212 o'clock position. There are 99 different kinds of moves allowed. As shown in the table below, each move rotates the hands of several clocks 90∘90^\circ clockwise.

move    clocks affected
 1         ABDE
 2         ABC
 3         BCEF
 4         ADG
 5         BDEFH
 6         CFI
 7         DEGH
 8         GHI
 9         EFHI

Input Format

99 integers, the starting positions of each clock's hand, separated by single spaces.

Here 0=120 = 12 o'clock, 1=31 = 3 o'clock, 2=62 = 6 o'clock, 3=93 = 9 o'clock.

Output Format

Output a shortest sequence of moves that makes all 99 clock hands point to 1212 o'clock. Output the move numbers in increasing order, separated by single spaces.

Sample Input

3 3 0
2 2 2
2 1 2

Sample Output

4 5 8 9

Constraints

Time limit: 1s, memory limit: 1024KiB for each test case.