#arc172c. C - Election

C - Election

问题陈述

今年的ATCoder市长选举有A和B两名候选人, NN 名选民投了票。

投票人被分配了从 11NN 的编号,投票人 ii (1iN)(1 \leq i \leq N) 为候选人 cic_i 投票。

现在,选票将被计算。

每次计票时,临时结果将作为以下三种结果之一公布:

-**结果A:**目前,候选人A得票较多。-**结果B:**目前,候选人B拥有更多票数。

-**结果C:**目前,候选人A和B的票数相同。

有一条关于计票顺序的规则:除投票人 11 以外的所有投票人的投票必须按其投票人编号的升序进行计算

贝尔斯。(投票人 11 的投票可随时计算。)

可以宣布多少种不同的临时结果?

临时结果的顺序是什么?设 sis_i 为计算第 ii 次投票 (1iN)(1 \leq i \leq N) 时报告的结果( ABC )。

临时结果的序列引用字符串 s1s2sNs_1 s_2 \dots s_N

以上为机器翻译结果,仅供参考。

Problem Statement

This year's AtCoder mayoral election has two candidates, A and B, and NN voters have cast their votes. The voters are assigned numbers from 11 to NN, and voter ii (1iN)(1 \leq i \leq N) voted for candidate cic_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 11 must be counted in ascending order of their voter numbers. (The vote from voter 11 may be counted at any time.)

How many different sequences of provisional results could be announced?

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

Constraints

  • NN is an integer such that 2N10000002 \leq N \leq 1000000.
  • Each of c1,c2,,cNc_1, c_2, \dots, c_N is A or B.

Input

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

NN

c1c2cNc_1 c_2 \cdots c_N

Output

Print the answer.

Sample Input 1

4
AABB

Sample 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 12341 \to 2 \to 3 \to 4.
  • The votes are counted in the order of voter 21342 \to 1 \to 3 \to 4.
  • The votes are counted in the order of voter 23142 \to 3 \to 1 \to 4.
  • The votes are counted in the order of voter 23412 \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.

Sample Input 2

4
AAAA

Sample Output 2

1

No matter the order of counting, the sequence of preliminary results will be AAAA.

Sample Input 3

10
BBBAAABBAA

Sample Output 3

5

Sample Input 4

172
AABAAAAAABBABAABBBBAABBAAABBABBABABABBAAABAAABAABAABBBBABBBABBABBBBBBBBAAABAAABAAABABBBAABAAAABABBABBABBBBBABAABAABBBABABBAAAABAABABBBABAAAABBBBABBBABBBABAABBBAAAABAAABAAAB

Sample Output 4

24

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