B - Polite Queue Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 233 点

問題文

バス停に N 人が一列に並んでいます。列の様子は長さ N の文字列 S で表され、 S の i 文字目が A なら前から i 番目の人は大人、 C なら子供です。

この町では、子供のすぐ後ろに大人が並んでいると、その大人が子供の面倒を見るのが行儀とされています。前から i 番目の人が子供で、前から i + 1 番目の人が大人であるような i の個数を求めてください。

制約

  • 1 \leq N \leq 100
  • S は A と C のみからなる長さ N の文字列

入力

入力は以下の形式で標準入力から与えられる。

N
S
  • 1 行目には、列に並んでいる人数 N が与えられる。
  • 2 行目には、列の様子を表す文字列 S が与えられる。

出力

条件を満たす i の個数を 1 行で出力せよ。


入力例 1

5
CACAA

出力例 1

2

入力例 2

4
AAAA

出力例 2

0

入力例 3

4
CCAA

出力例 3

1

入力例 4

31
CACCCCACCCAACAAAACCCCCACCACCAAA

出力例 4

7

入力例 5

43
ACACCCACACCACAAAAACCACCAACCCACAACCCACCCCCAA

出力例 5

11

Score : 233 pts

Problem Statement

N people are standing in a single line at a bus stop. The state of the line is represented by a string S of length N: if the i-th character of S is A, the i-th person from the front is an adult; if it is C, they are a child.

In this town, it is considered good manners for an adult to look after a child standing directly in front of them. Find the number of indices i such that the i-th person from the front is a child and the (i + 1)-th person from the front is an adult.

Constraints

  • 1 \leq N \leq 100
  • S is a string of length N consisting only of A and C.

Input

The input is given from Standard Input in the following format:

N
S
  • The first line contains N, the number of people in the queue.
  • The second line contains the string S representing the state of the queue.

Output

Print the number of indices i satisfying the condition on a single line.


Sample Input 1

5
CACAA

Sample Output 1

2

Sample Input 2

4
AAAA

Sample Output 2

0

Sample Input 3

4
CCAA

Sample Output 3

1

Sample Input 4

31
CACCCCACCCAACAAAACCCCCACCACCAAA

Sample Output 4

7

Sample Input 5

43
ACACCCACACCACAAAAACCACCAACCCACAACCCACCCCCAA

Sample Output 5

11