No.3655 Adjacent Pairs in Triplets
Problem Statement
A string of length $3$ is called a good string if it consists of exactly $2$ kinds of characters and contains a place where the same character appears consecutively.
For example, MMA and 144 are good strings, but 121 and ABC are not.
You are given a string $S$ consisting only of uppercase English letters and digits. Find the number of contiguous substrings of length $3$ in this string that are good strings.
Substrings taken from different positions are counted separately, even if they are equal as strings.
Constraints
- $1 \le |S| \le 2 \times 10^5$
- Each character in $S$ is an uppercase English letter or a digit
Input
$S$
Output
Print the answer in $1$ line.
Sample
Sample 1
Input
MMA022
Output
2
The parts MMA and 022 each satisfy the condition, so print $2$.
Sample 2
Input
AAABBBCCCAAABBBCCC
Output
10
Substrings such as AAA contain only $1$ kind of character, so they are not counted in the answer.
Sample 3
Input
A11B22C
Output
4
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
くらげ
sepa38