D - A..B..C 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

文字列 S が与えられます。

S の中に A, B, C がこの順に等間隔に並んでいる場所が何箇所あるか求めてください。

厳密には、3 つの整数の組 (i,j,k) であって、以下の条件をすべて満たすものの個数を求めてください。 ここで、|S|S の長さを、S_xSx 文字目を表すものとします。

  • 1\leq i<j<k\leq |S|
  • j-i = k-j
  • S_i= A
  • S_j= B
  • S_k= C

制約

  • S は英大文字からなる長さ 3 以上 100 以下の文字列

入力

入力は以下の形式で標準入力から与えられる。

S

出力

答えを出力せよ。


入力例 1

AABCC

出力例 1

2

(i,j,k)=(1,3,5),(2,3,4)2 つの組が条件を満たします。


入力例 2

ARC

出力例 2

0

入力例 3

AABAAABBAEDCCCD

出力例 3

4

Score : 200 points

Problem Statement

A string S is given.

Find how many places in S have A, B, and C in this order at even intervals.

Specifically, find the number of triples of integers (i,j,k) that satisfy all of the following conditions. Here, |S| denotes the length of S, and S_x denotes the x-th character of S.

  • 1 \leq i < j < k \leq |S|
  • j - i = k - j
  • S_i = A
  • S_j = B
  • S_k = C

Constraints

  • S is an uppercase English string with length between 3 and 100, inclusive.

Input

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

S

Output

Print the answer.


Sample Input 1

AABCC

Sample Output 1

2

There are two triples (i,j,k) = (1,3,5) and (2,3,4) that satisfy the conditions.


Sample Input 2

ARC

Sample Output 2

0

Sample Input 3

AABAAABBAEDCCCD

Sample Output 3

4