AtCoder Regular Contest 172
C
Election
AtCoder
⌀ 1498
原题
← BD →
翻译中…

Problem Statement

翻译中…

This year's AtCoder mayoral election has two candidates, A and B, and $N$ voters have cast their votes. The voters are assigned numbers from $1$ to $N$, and voter $i$ $(1 \leq i \leq N)$ voted for candidate $c_i$.

翻译中…

Now, the votes will be counted. As each vote is counted, the provisional result will be announced as one of the following three outcomes:

翻译中…
  • Result A: Currently, candidate A has more votes.
  • Result B: Currently, candidate B has more votes.
  • Result C: Currently, candidates A and B have the same number of votes.
翻译中…

There is a rule regarding the order of vote counting: votes from all voters except voter $1$ must be counted in ascending order of their voter numbers. (The vote from voter $1$ may be counted at any time.)

翻译中…

How many different sequences of provisional results could be announced?

翻译中…

What is a sequence of provisional results?Let $s_i$ be the result (A, B, or C) reported when the $i$-th vote $(1 \leq i \leq N)$ is counted. The sequence of provisional results refers to the string $s_1 s_2 \dots s_N$.

翻译中…

Constraints

翻译中…
  • $N$ is an integer such that $2 \leq N \leq 1000000$.
  • Each of $c_1, c_2, \dots, c_N$ is A or B.
翻译中…

Input

翻译中…

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

翻译中…

N
c_1 c_2 \cdots c_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
4
AABB
Output #1
3
In this sample input, there are four possible orders in which the votes may be counted: - The votes are counted in the order of voter $1 \to 2 \to 3 \to 4$. - The votes are counted in the order of voter $2 \to 1 \to 3 \to 4$. - The votes are counted in the order of voter $2 \to 3 \to 1 \to 4$. - The votes are counted in the order of voter $2 \to 3 \to 4 \to 1$. The sequences of preliminary results for these will be `AAAC`, `AAAC`, `ACAC`, `ACBC` from top to bottom, so there are three possible sequences of preliminary results.
Input #2
4
AAAA
Output #2
1
No matter the order of counting, the sequence of preliminary results will be `AAAA`.
Input #3
10
BBBAAABBAA
Output #3
5
Input #4
172
AABAAAAAABBABAABBBBAABBAAABBABBABABABBAAABAAABAABAABBBBABBBABBABBBBBBBBAAABAAABAAABABBBAABAAAABABBABBABBBBBABAABAABBBABABBAAAABAABABBBABAAAABBBBABBBABBBABAABBBAAAABAAABAAAB
Output #4
24
题目信息
题号
arc172_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。