Time limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard Input
Output
Standard output
Everybody knows that the berland citizens are keen on health, especially students. berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to play a simple game. AllNPeople
Who came to the barbecue sat in a circle (thus each person has ed a unique indexBIFrom
0NRole-Disposition 1). The person number 0 started the game (this time it was Vasya). All turns in the game were numbered by integers starting from
1. IfJ-Th turn was made by the person with indexBI,
Then this person acted like that:
- He pointed at the person with index (BILimit + limit 1)MOD nEither
With an elbow or with a nod (X mod yIs the remainder after dividingXByY);
- IfJLatency ≥ 4 and the players who had turns numberJExecutor-cores 1,JAccept-limit 2,JExecutor-cores 3,
Made during their turns the same moves as playerBIOn
The current turn, then he had drunk a glass of juice;
- The turn went to Person Number (BILimit + limit 1)MOD n.
The person who was pointed on the last turn did not make any actions.
The problem was, Vasya's drunk too much juice and can't remember the goal of the game. however, Vasya's got the recorded sequence of all the participants 'actions (including himself ). now Vasya wants to find out the maximum amount of juice he cocould drink if
He played optimally well (the other players 'actions do not change). Help him.
You can assume that in any scenario, there is enough juice for everybody.
Input
The first line contains a single integerN(4 cores ≤ CoresNLimit ≤00002000)
-The number of participants in the game. The second line describes the actual game:I-Th character of this line equals 'A ',
If the participant ant who movedI-Th pointed at the next person with his elbow, and 'B ',
If the participant ant pointed with a nod. The game continued for at least 1 and at most 2000 turns.
Output
Print a single integer-the number of glasses of juice Vasya cocould have drunk if he had played optimally well.
Sample test (s) Input
4abbba
Output
1
Input
4abbab
Output
0
Note
In both samples Vasya has got two turns-1 and 5. in the first sample, Vasya cocould have drunk a glass of juice during the previous th turn if he had pointed at the next person with a nod. in this case, the sequence of moves wowould look like "abbbb ". in the second
Sample Vasya wouldn't drink a single glass of juice as the moves stored med during turns 3 and 4 are different.
Explanation: although the question is very long, it is not difficult to analyze it. I will give you n people, start to report A or B, and the first person starts to report data in turn, if the first three of you repeatedly report the same letter, you can have a drink. How many drinks do you have before?
#include <cstdio>#include<iostream>using namespace std;char s[2005];int main() {int n,i;int cnt = 0;scanf("%d%s", &n, s);for( i = n; s[i]; i+=n) {if(s[i-1] == s[i-2] && s[i-2] == s[i-3]){cnt++;}}printf("%d\n", cnt);}