Time limit
1s
Memory limit
128 MB
There are four die-shaped cubes. Each face of each cube is painted one of red (R), green (G), blue (B), or yellow (Y). The cubes are stacked into a column, and each of the four side faces of the column must show all four colors exactly once. Compute how many different columns can be made.
![]() | ![]() | ![]() | ![]() |
| Cube 1 | Cube 2 | Cube 3 | Cube 4 |
| Figure 1 |
![]() | ![]() | ![]() |
| Figure 2 | Figure 3 | Figure 4 |
The stacking order is fixed. Cube 1 is placed at the bottom, then cube 2, cube 3, and cube 4 are placed above it in that order. Each cube may be rotated freely before it is placed. Using the four cubes in Figure 1, the columns shown in Figures 2 and 3 both satisfy the condition.
If rotating the entire column sideways makes two columns look the same, they are counted as one column. Therefore the columns in Figures 3 and 4 are the same column. Columns with different colors on the top face are different, while the bottom face is not visible and is ignored.
Four lines are given. The first, second, third, and fourth lines describe cube 1, cube 2, cube 3, and cube 4, respectively. Each line consists of six uppercase letters, each one of R, G, B, and Y. The six letters give the colors of faces ga, na, da, ra, ma, and ba in Figure 5, in that order.

Figure 5
Print the number of different columns that satisfy the condition. If no such column can be made, print 0.