There are 26 beads in total, 13 gray and 13 yellow, split between two circles with 13 beads on each circle. Each circle can be freely rotated clockwise or counterclockwise.
The upper and lower circles are joined by a smaller circle that sits between them. Rotating this small circle 180 degrees in the plane of the board swaps, as a block, the three bottommost beads of the upper circle with the three topmost beads of the lower circle.
The goal is to arrange the beads so that only gray beads remain on the upper circle and only yellow beads remain on the lower circle. Write a program that finds the minimum number of 180-degree rotations of the connecting small circle needed to reach this arrangement. Rotating either large circle clockwise or counterclockwise does not count toward this total.
The input consists of several test cases. Each test case is a single line describing the colors of the beads on the two circles. Every line is a string of length 26 made up of thirteen y characters and thirteen g characters.
The first 13 characters of a line give the colors of the upper circle's beads in clockwise order, and the remaining 13 characters give the colors of the lower circle's beads in clockwise order. y is a yellow bead and g is a gray bead.
The input continues over multiple lines until end of file, and every line, including the last one, ends with a newline.
For each test case, print on its own line the minimum number of times the connecting small circle must be rotated so that only gray beads remain on the upper circle and only yellow beads remain on the lower circle.