An valid alphabracket string consists of a series of upper and lowercase letters, and must be in the form of:
For example, BAaCcb is a valid alphabracket string while ABab is not.
Given a string S consisting of only uppercase and lowercase letters, determine how many non-empty substrings of S are valid alphabracket strings.
The first and only line of input will contain one string, S.
The output should contain one integer, the number of non-empty substrings of S which are valid alphabracket strings.
Subtask 1 (16%): 1 ≤ length of string ≤ 300.
Subtask 2 (18%): 1 ≤ length of string ≤ 2000.
Subtask 3 (14%): 1 ≤ length of string ≤ 100000, the string will only consist of 'A' and 'a', and all 'A's will come before any 'a'.
Subtask 4 (23%): 1 ≤ length of string ≤ 100000, the string will only consist of 'A' and 'a'.
Subtask 5 (13%): 1 ≤ length of string ≤ 100000.
Subtask 6 (16%): 1 ≤ length of string ≤ 2000000.
Subtask 7 (0%): Sample Testcases.
BAaCcb
4
ABab
0
aAaAa
3
Subtask | Score |
---|---|
1 | 16 |
2 | 18 |
3 | 14 |
4 | 23 |
5 | 13 |
6 | 16 |
7 | 0 |