問題一覧 > 通常問題

No.3655 Adjacent Pairs in Triplets

レベル : / AI推定難易度 : 130 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 107
作問者 : くらげ / テスター : sepa38 t5ugu dyktr_06 yuusaan
お気に入りにしたユーザー ProblemId : 13905 / 自分の提出
問題文最終更新日: 2026-08-29 16:08:24
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
MMA Contest 022 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。