Blown Garland
Contest: Codeforces Round 392 (Div. 2)
Difficulty rating: 1100
Tags: brute force, implementation, number theory

Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.

Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working.

It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like "RYBGRYBGRY", "YBGRYBGRYBG", "BGRYB", but can not look like "BGRYG", "YBGRYBYGR" or "BGYBGY". Letters denote colors: 'R' — red, 'B' — blue, 'Y' — yellow, 'G' — green.

Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.

Input format:
The first and the only line contains the string s (4 ≤ |s| ≤ 100), which describes the garland, the i-th symbol of which describes the color of the i-th light bulb in the order from the beginning of garland:

- 'R' — the light bulb is red,
- 'B' — the light bulb is blue,
- 'Y' — the light bulb is yellow,
- 'G' — the light bulb is green,
- '!' — the light bulb is dead.

The string s can not contain other symbols except those five which were described.

It is guaranteed that in the given string at least once there is each of four letters 'R', 'B', 'Y' and 'G'.

It is guaranteed that the string s is correct garland with some blown light bulbs, it means that for example the line "GRBY!!!B" can not be in the input data.

Output format:
In the only line print four integers kr, kb, ky, kg — the number of dead light bulbs of red, blue, yellow and green colors accordingly.

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
In the first example there are no dead light bulbs.

In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements.

Example input:
RYBGRYBGR

Example output:
0 0 0 0

Example input:
!RGYB

Example output:
0 1 0 0

Editorial:
Four consecutive bulbs should not be of the same color, and it is four possible colors, so the color of the fifth bulb is the same as the first bulb has, the color of the sixth is the same as the second bulb has, it means that the color of the n-th bulb equals the color of the (n - 4)-th bulb.
Thus, the coordinates of all bulbs of the same color equal in module 4.
According to the conditions of the problem the coordinate of at least one light bulb of each color is given, so we can restore the garland and by one pass count the number of blown bulbs.
By one pass we learn how numbers in module 4 correspond to the colors. By the second pass we know the place of the bulb and count the number of blown bulbs of each color.
The asymptotic behavior of the solutions is  — O(n).
There is also a second solution:
You can just fix order of first four light bulbs by bruteforce (there is only 4! = 24 variants), checking the conformity of each option of the given garland. By finding the color of the first four bulbs we easily recreate the garland with working lights and count the number of blown bulbs.
At worst this decision will work for 24·n.