
marble circular tiles — half yellow, half gray — are distributed between two circles, each with tiles. The tiles in each circle can be freely rotated clockwise or counterclockwise. The upper and lower circles are connected by a smaller bridging circle, which can also be rotated degrees, effectively swapping the three bottommost tiles of the upper circle with the three topmost tiles of the lower circle. The goal is to have all gray tiles in the upper circle and all yellow tiles in the lower circle, minimizing the number of bridging circle rotations.
The input consists of several lines, each describing a separate test case and the initial arrangement of tiles. Each line is a permutation of letters "y" and letters "g". The first half of each line describes, in clockwise order, the arrangement of tiles in the upper circle; the second half describes the lower circle. Each letter "y" corresponds to a yellow tile, and each "g" to a gray tile.
For each test case, output the required minimum number of rotations in a separate line.
Example 1