1229 - Periodic Operation

Time Limit : 10 Second

Memory Limit : 128 MB

Submission: 24

Solved: 6

Description
Rubik's Cube is one of the most popular toys in the world. The job of recovering 6 faces is interesting. Now it can be solved by computer very efficiently, but this time I won't give you such a hard assignment.

A Rubik's Cube player may find that any series of certain operations on a Cube is periodic, which means that given a series of operations, if performed on a recovered cube successively for a certain times, the cube will be recovered again. The minimum number of times required is called the period of that series of operations.

Now you are asked to calculate the period of some given series of operations.
Input
Input terminates with EOF.
Each case has a line describing the series of operations.
Any series is composed of unit operations of the following 18 ones:
U U' U2 R R' R2 F F' F2
D D' D2 L L' L2 B B' B2
Any two operations is separated by a space.
Any series has no more than 100 operations and no less than 1 operation.
The function of the above operation is explained in the following figure:
Output
For each case output one number indicating the period in one line.
sample input
F
R2 R2
U R' U' R
sample output
4
1
6
hint
1. Before scrambling, each face of the cube has a unique color. 2. The cube is recovered when any face is composed of only one color.
source
Isun
© 2015 HUST ACMICPC TEAM. All Right Reserved.