#P6. [CSP-S 2023] 2-pop game

[CSP-S 2023] 2-pop game

Description

Xiao L is currently playing a low-level version of 2-pop game, which is one-dimensional and can only eliminate two adjacent elements at a time.

Now, he has a string of length nn consisting only of lowercase letters. We call a string erasable if and only if it can be manipulated several times to make it an empty string.

Each operation can delete two adjacent identical characters from the string, and the remaining string will be concatenated together after the operation.

Xiao L wants to know how many non empty continuous substrings of this string are removable.

Input

The first line of input contains a positive integer nn, representing the length of the string.

The second line of input contains a string of length nn consisting only of lowercase letters, representing the string asked in the question.

Output

Output a line containing an integer representing the answer to the question asked.

Samples

8
accabccb
5

Tips

[Sample Input 1 Explanation]

There are a total of 55 continuous substrings that can be eliminated, namely ccaccaccbccbaccabccb.

[Example 2]

See game/game2.in and game/game2.ans in the player directory.

[Example 3]

See game/game3.in and game/game3.ans in the player directory.

[Example 4]

See game/game4.in and game/game4.ans in the player directory.

[Data Range]

For all test data, there is 1n2×1061 \le n \le 2 \times 10^6, and the query string is only composed of lowercase letters.

Test point nn\leq Special properties
151\sim 5 1010 None
676\sim 7 800800
8108\sim 10 80008000
111211\sim 12 2×1052\times 10^5 A
131413\sim 14 B
151715\sim 17 None
182018\sim 20 2×1062\times 10^6

Special property A: Each character in a string is independently and equally selected from the character set.

Special property B: A string is composed only of a and b.