問題一覧 > 通常問題

No.2419 MMA String 2

レベル : / AI推定難易度 : 500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 165
作問者 : dyktr_06 / テスター : Nafmo2 LaFolia13 hikikomori sepa38 Seed57_cash Udon ryota2357
お気に入りにしたユーザー ProblemId : 9701 / 自分の提出
問題文最終更新日: 2023-08-12 13:31:36
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 016 (順位表) の他の問題:

Problem Statement

An MMA string is a string of $3$ characters that consists of $2$ distinct letters and whose $1$st and $2$nd characters are the same.

You are given a string $S$ consisting only of uppercase English letters. Find the number of subsequences of $S$, not necessarily contiguous, that are MMA strings.

Note that even if the extracted subsequences are equal as sequences, they are counted as different ways of extraction if the sets of chosen positions differ.


Constraints

  • $3 \leq | S | \leq 2 \times 10^5$
  • $S$ is a string consisting only of uppercase English letters

Input

The input is given from Standard Input in the following format.

$S$  

Output

Output the answer to the problem on a single line.

Sample

Sample 1
Input
CIRCLEMMA
Output
6

The following $6$ subsequences, not necessarily contiguous, are MMA strings.

  • CCL, extracting characters $1, 4, 5$
  • CCE, extracting characters $1, 4, 6$
  • CCM, extracting characters $1, 4, 7$
  • CCM, extracting characters $1, 4, 8$
  • CCA, extracting characters $1, 4, 9$
  • MMA, extracting characters $7, 8, 9$

Sample

Sample 2
Input
MMACONTESTISFORBEGINNERS
Output
82

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。