cswork / OAOpen practice workspace

AmazonOA #125

Count Special Substrings in a DNA Sequence

Estimated MediumJudge-ready

Topics (AI-labelled)StringsTwo Pointers

For length 2, the two characters must be equal; for length greater than 2, the first and last characters must be equal and the middle must contain exactly one kind of character. Count all qualifying substrings by index.

Input

One line with a lowercase string of length 1..300000.

Output

Output a single integer answer.

Example 1

Input:

xyyx

Output:

2

Example 2

Input:

aaaa

Output:

6

Example 3

Input:

aabaa

Output:

3

Example notes

Example 1: yy and xyyx are valid, 2 in total. Example 2: 3 of length 2, 2 of length 3 and 1 of length 4, 6 in total. Example 3: one aa on each side plus aba in the middle, 3 in total.

Editorial

Loading solution…