Problem:
Score : 600 points

Problem Statement

You are given a string s consisting of A, B and C.

Snuke wants to perform the following operation on s as many times as possible:

Choose a contiguous substring of s that reads ABC and replace it with BCA.

Find the maximum possible number of operations.

Constraints

1 \leq |s| \leq 200000

Each character of s is A, B and C.

Input

Input is given from Standard Input in the following format:

s

Output

Find the maximum possible number of operations.

Sample Input 1

ABCABC

Sample Output 1

3

You can perform the operations three times as follows: ABCABC → BCAABC → BCABCA → BCBCAA. This is the maximum result.

Sample Input 2

C

Sample Output 2

0

Sample Input 3

ABCACCBABCBCAABCB

Sample Output 3

6

Solution in Pascal (FPC 2.6.2) (judge verdict: Accepted)

var t:longint;        //A的个数在32位范围内
    a:int64;          //结果会爆int
    c:char;           //滚动省空间
begin
  while not eoln do   //一直读到换行
  begin
    read(c);          //读入一个
    if c='A' then     //如果是A
      inc(t);         //记录值加一
    if c='B' then     //如果是B
    begin
      read(c);        //读入
      if c='C' then   //如果是C（有效字符）
      begin
        inc(a,t);     //结果加记录值
        continue;     //下一个循环
      end
      else            //如果不是C（无效字符）
        if c='A' then //如果是A（因为A被吞了）所以要分开计算
          t:=1        //记录值为1
        else          //否则
          t:=0;       //记录值为0
    end;
    if c='C' then     //如果是单个的C（无效字符）
      t:=0;           //记录值为0
  end;
  writeln(a);         //输出结果
end.