One nice summer day while Mirko was drinking lemonade in his room…
"Big brother!", yells Stanko.
"I wonder sometimes which of the two of us is the big one. What is it?", Mirko asked.
"Listen carefully! In the backyard I have pebbles arranged in a circle. Some of the pebbles are black, some are white. I will do the following: between any two neighbouring pebbles of the same colour I will insert a black pebble, and between any two neighbouring pebbles of different colours I will insert a white pebble. At that point there will be pebbles in the circle, so I will remove the starting pebbles so that only the newly added pebbles remain. And all this I intend to do exactly times. And then you are to determine my starting circle.", said Stanko long-windedly.
"Ha! I shall not fall prey to your trickery! I can see that it is not necessarily possible to know exactly what the starting circle was, but I can count the number of distinct starting circles that give the same result as your circle after exactly of those weird transformations of yours", answered Mirko.
You are given the configuration of the circle before Stanko performed the transformation described above times.
Write a program that determines the number of distinct starting circles that give the same circle after transformations as Stanko's original circle does after transformations.
Two configurations of pebbles are considered to be the same circle if one can be gotten from the
other by rotating it any number of positions. For example BBW
and BWB
is the same circle whereas
BBWWBW
and WWBBWB
are not.
Input Specification
The first line of input contains two integers and , , , where is the number of pebbles in the circle and is the number of transformations made by Stanko.
The second line contains exactly characters B
or W
representing Stanko's original circle.
Output Specification
Output the number of possible distinct starting circles on a single line.
Sample Input 1
3 1
BBW
Sample Output 1
2
Explanation for Sample Output 1
The circles BBW
and WBW
become circle BWW
after one transformation.
Sample Input 2
6 2
WBWWBW
Sample Output 2
3
Comments
Wait shouldn't the first test case be:
Not:
Because the explanation says
Also 3 1 BBW should return
0 not 2, or am I just missing something.