Denis had a Rubik's cube
covered with pretty patterns on his table.
When Denis quit the room, Vadik took the cube and made a few rotations.
But he got scared suddenly:
what if Denis get angry about the broken patterns?
Vadik wanted to restore the cube to the original state,
but could not find a way.
Vadik heard somewhere that if one repeats a sequence of rotations again
and again, one would get the original pattern at some point.
Given this is true, it is possible to revert the cube until Denis returns.
How many times does Vadik need to apply his sequence of rotations
in order to revert the cube to the original state?
The description of rotations applied by Vadik in the form of a string
consisting of letters “U”, “D”, “L”, “R”, “F” and “B”
(upper or lower case).
They mean rotations of top, bottom, left, right, front and back faces,
Lowercase letters mean 90-degree clockwise rotations, uppercase letters mean
90-degree counterclockwise rotations.
The string is not empty and its length does not exceed 105.
Output the number of times Vadik needs to apply his sequence of rotations in
order to get the original pattern.
Problem Author: Grigoriy Nazarov
Problem Source: Ural SU Team.GOV Contest. Petrozavodsk Summer Session, August 2011