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. All
n people who came to the barbecue sat in a circle (thus each person received a unique index
bi from 0 to
n-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. If the
j-th turn was made by the person with index
bi, then this person acted like that:
-
he pointed at the person with index (bi+1)modn either with an elbow or with a nod (xmody is the remainder after dividing x by y);
-
if j≥4 and the players who had turns number j-1, j-2, j-3, made during their turns the same moves as player bi on the current turn, then he had drunk a glass of juice;
-
the turn went to person number (bi+1)modn.
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 could drink if he played optimally well (the other pla
yers' actions do not change). Help him.
You can assume that in any scenario, there is enough juice for everybody.
Note
In both samples Vasya has got two turns − 1 and 5. In the first sample, Vasya could have drunk a glass of juice during the fifth turn if he had pointed at the next person with a nod. In this case, the sequence of moves would look like "abbbb". In the second sample Vasya wouldn't drink a single glass of juice as the moves performed during turns 3 and 4 are different.