Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
Language:
New Stone-Forfex-Cloth Game
Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 1528Accepted: 622

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.

Sample Input

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

Sample Output

3
1
4

Source

POJ Monthly,汪艺杰

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator