import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long calc(string s) {
    long ans = 0; // int だと overflow
    int a = 0; // a の個数
    int p = 0;
    while (p < s.length) {
        if (s[p] == 'A') {
            a++;
            p++;
        }
        else if (s[p] == 'B') {
            if (a > 0 && p + 1 < s.length && s[p + 1] == 'C') {
                ans += a;
                p += 2;
            }
            else {
                a = 0;
                p++;
            }
        }
        else {
            a = 0;
            p++;
        }
    }
    return ans;
}

void main() {
    string s = read!string;
    writeln(calc(s));
}
