#P2232. New Stone-Forfex-Cloth Game

New Stone-Forfex-Cloth Game

Description

Acm is a clever boy, and he developed a new game form the old Stone-Forfex-Cloth game.

In this game, a number of children sit in a circle, each one shows a gesture (one of the Stone, the Forfex and the Cloth), which can't be changed in the whole game. Then a randomly chosen child (we call him player A) compares his gesture with the one on his anticlockwise (we call him play B) direction. And the loser should jump out of the circle. This operation continues until there is only one child left, which is the winner. Of course the winner is decided by both the gestures the children show and the order to compare. Your task is to tell the total number of possible winners.

The game obeys the following rulers:

  1. Forfex beat Cloth.
  2. Cloth beat Stone.
  3. Stone beat Forfex.
  4. If it is a draw, play A wins.

Input

The input contains several test cases. In each case, the first line contains an integer N (the number of children, 1 <= N <= 1000), and the second line contains N capitals including 'S', 'F' and 'C, which are separated by a single space and represent the gestures of N children in clockwise order. Here 'S' expresses the Stone, 'F' expresses the Forfex, and 'C' expresses the Cloth.

Output

For each case, output the total number of possible winners in a single line.

3
C S F
2
S C
4
S S S S
3
1
4

Source

POJ Monthly

,汪艺杰