Finding Maximal Non-Trivial Monotones

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

In this problem we will be dealing with character sequences, often called strings. A sequence is non-trivial if it contains at least two elements.

Given a sequence ss, we say that a chunk s_i,,s_js\_i , \dots , s\_j is monotone if all its characters are equal, and we say that it is maximal if this chunk cannot be extended to left or right without losing the monotonicity.

Given a sequence composed only of characters “a” and “b”, determine how many characters “a” occur in non-trivial maximal monotone chunks.

입력

The input consists of two lines. The first line contains a single integer NN, where 1N1051 ≤ N ≤ 10^5. The second line contains a string with exactly NN characters, composed only of the characters “a” and “b”.

출력

Print a single line containing an integer representing the total number of times the character “a” occurs in non-trivial maximal monotone chunks.