Given a circular row of R, G, B cells and a three-cell local update rule, count each color after K synchronous rounds with K up to 1e9.
Medium7SimulationMathNo attempts yetTime limit1sMemory limit256 MBJihun prepared a spinner for a prize event. The circular board is divided into N equal parts, and each part is painted red, green, or blue. A participant picks one of the three colors. The board is spun, and everyone whose color matches the color of the part the spinner stops on receives a prize. If a of the N parts are red, b are green and c are blue, then the chance of each color is a/N, b/N and c/N. So if nobody knows which part carries which color, all three colors are equally likely.
Jihun checked which colors the participants had picked and found that one of the three colors was picked far more often. The reason was that someone had looked at the spinner and told a few acquainted participants which color covered the most parts. Jihun therefore wants to repaint the whole board.
Number the parts 1 to N clockwise. The left part of part i is part i−1 and the right part is part i+1, where the left part of part 1 is part N and the right part of part N is part 1.
One round of repainting works as follows. Every part changes color at the same time, and for each part P you look at the three colors painted on the left part of P, on P itself, and on the right part of P.
Jihun repeated this round K times in total. Find how many parts carry each color after the K rounds.
The first line contains N and K, separated by a space.
The second line contains a string of length N that lists the color painted on every part, starting at part 1 and going clockwise. Red is given as R, green as G and blue as B.
1≤N≤100000, 1≤K≤109
Print one line holding the number of red parts, the number of green parts and the number of blue parts after all K rounds, in that order, separated by single spaces.