Question
Max Operations
You are given a string S of length n which consists of characters 'A' and 'B'. You can do the following operation:
  • Choose an index 1 ≤ i ≤ n−1 such that s[i] = 'A' and s[i+1] = 'B'. Then, swap s[i] and s[i+1].
You are only allowed to do the operation at most once for each index 1 ≤ i ≤ n-1. However, you can do it in any order you want.
Find the maximum number of operations that you can carry out.
Input
The first line of the input contains a single integer N, denoting the size of an array.
The second line of the input contains a string s.

Constraints
1 ≤ N ≤ 105
si will either be 'A' or 'B'.
Output
Print an integer, representing the maximum number of operations.
Example
Sample Input
4
AABB
Sample Output
3
Explanation
In this case, we can do an operation on i = 2 to form ABAB, then another operation on i = 3 to form ABBA, and finally another operation on i = 1 to form BABA. Note that even though at the end, s2 = A and s3 = B, we cannot do an operation on i = 2 again as we can only do the operation at most once for each index.

Online