eolymp
bolt
Try our new interface for solving problems
Problems

Bridged Marble Rings

Bridged Marble Rings

\includegraphics{https://static.e-olymp.com/content/ac/ac24c21b93af5c4796c4b18ec545be9c2d8d8937.jpg} \textbf{26} marbles --- half yellow and half gray --- are distributed between two circles of \textbf{13} marbles each. The marbles in each circle can be freely rotated clockwise or counterclockwise. The upper and lower circles are bridged by a smaller circle, which rotates --- in the plane of the board --- \textbf{180} degrees, effectively exchanging the three bottommost marbles of the upper circle with the three uppermost marbles of the lower one. The goal is to get all gray marbles to the upper circle and all yellow marbles to the lower one while minimizing the number of times the bridging circle is rotated. \InputFile The input is a series of lines, where each line describes an initial board configuration. Each line is a permutation of 13 \textbf{y}’s and 13 \textbf{g}’s. The first half of the line describes the clockwise configuration of the upper circle, and the rest of the line describes the clockwise configuration of the lower one. Of course, each \textbf{y} corresponds to a yellow marble, and each \textbf{g} corresponds to a gray one. The input file will include multiple test cases. Each test case consists of a single line containing some permutation of the string \textbf{y^13g^13}. All lines (including the last one) are terminated with a newline. The newline immediately follows the last letter on the line. \OutputFile For each input case, you should print the minimum number of bridge rotations on a single line.
Time limit 1 second
Memory limit 64 MiB
Input example #1
gggggggggggggyyyyyyyyyyyyy
yyyyyggggggggyyyygggggyyyy
gyyygyggyyygyyggyyggggyygg
ygygygygygygygygygygygygyg
Output example #1
0
2
5
6
Source Pacific North West Region Programming Contest, 2007