Welcome to ZOJ
Information
Problems
Runs
Statistics
Ranklist
Clarification
82 - ZOJ Monthly, August 2009 - F
Pyraminx II

Time Limit: 5 Seconds      Memory Limit: 65536 KB      Special Judge

Refer to Pyraminx (ZOJ 3074), B.B. has been tired with the rubik's cube and bought a pyraminx for many days. A pyraminx is a special kind of rubik's cube, which looks like a pyramid. Fig-1 shows a pyraminx, it's also the standard arrangement of a pyraminx. A pyraminx can be rotated in 8 different ways: rotate clockwise 120° or counter clockwise 120° around one of the four vertexes. Fig-2 demonstrates the operations where '+' for clockwise and '-' for counter clockwise. Simply, we use 'A+' for rotating the pyraminx 120° clockwise around vertex 'A', and 'A-' for counter clockwise rotating around 'A'. Other vertexes perform in the same way.

For each pyraminx and its arrangement, there are 12 ways to express. Fig-3 shows the standard arrangement's three different expressions. They're generated by expanding the pyraminx in vertex 'A'. You can also expand the pyraminx in other three vertexes to generate other expressions. So there are 12 ways to express the pyraminx. Note that all the 12 expressions are EQUIVALENT.

Thanks for your help, B.B. is no longer confused with the rotating. But this time, she wants to know how many operations she should do at least to perform a new pyraminx of the goal arrangement from the standard arrangement.

Input

There are multiple cases (up to 45).

For each case, it contains 6 lines. It shows one of the 12 expressions of the goal arrangement. The format of the input is shown in sample input, use spaces to seperate characters, there are no trailing spaces. Use 'R' for red, 'G' for green, 'B' for blue and 'Y' for yellow.

There is a blank line after each case. Input will end with a single line "#".

Output

If we can't perform the new pyraminx of the goal arrangement from the standard arrangement in 11 steps, just output "IMPOSSIBLE"; otherwise output the operation in each step in the following format. (See sample output for more details.)

START
[operation 1]
[operation 2]
......
END

Sample Input

    /G\        /B\        /R\
  /G\G/G\    /Y\B/B\    /R\R/R\
/R\R/B\G/G\/Y\Y/Y\G/G\/B\B/B\B/B\
           \R/R\R/Y\Y/
             \G/Y\Y/
               \Y/

    /B\        /R\        /G\
  /R\B/Y\    /B\R/Y\    /G\G/G\
/B\B/G\G/G\/Y\Y/Y\Y/Y\/G\G/B\Y/Y\
           \R/R\R/B\B/
             \B/R\R/
               \R/

    /B\        /B\        /G\
  /R\B/Y\    /B\R/Y\    /G\G/G\
/B\R/G\G/G\/Y\Y/Y\Y/Y\/G\G/B\Y/Y\
           \R/R\R/B\B/
             \B/R\R/
               \R/

    /G\        /R\        /Y\
  /G\G/G\    /R\R/R\    /Y\Y/Y\
/Y\Y/Y\Y/Y\/G\G/G\G/G\/R\R/R\R/R\
           \B/B\B/B\B/
             \B/B\B/
               \B/

#

Sampel Output

START
A+
B-
END
START
A-
C+
B-
D+
END
IMPOSSIBLE
START
B+
END

Author: MO, Luyi
Submit    Status