import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

S = str(input())
S = S.replace('BC', 'D')

ans = 0
a = 0
d = 0
flag = False
for s in S[::-1]:
    if s=='D':
        if a>=1:
            ans += a*d
            a = 0
        d += 1
        flag = True
    elif s=='A':
        if flag:
            a += 1
    else:
        ans += a*d
        a,d = 0,0
        flag = False
ans += a*d

print(ans) import sys sys import math math from collections import defaultdict sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 def input():
    return sys.stdin.readline()[:-1] input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 def I(): return int(input()) I def II(): return map(int, input().split()) II def III(): return list(map(int, input().split())) III def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

################# Line if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

################# N<=0 N 0 return [[]]*num [[]]*num [[]] [] num elif num==1:
        return [I() for _ in range(N)]
     num==1 num 1 I() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) I() I return [I() for _ in range(N)] [I() for _ in range(N)] tuple(II()) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) tuple(II()) tuple II() II read_all = [tuple(II()) for _ in range(N)] read_all [tuple(II()) for _ in range(N)] return map(list, zip(*read_all)) map(list, zip(*read_all)) map list zip(*read_all) zip *read_all read_all N N num num S = str(input()) S str(input()) str input() input S = S.replace('BC', 'D') S S.replace('BC', 'D') S.replace S replace 'BC' 'D' ans = 0 ans 0 a = 0 a 0 d = 0 d 0 flag = False flag False for s in S[::-1]:
    if s=='D':
        if a>=1:
            ans += a*d
            a = 0
        d += 1
        flag = True
    elif s=='A':
        if flag:
            a += 1
    else:
        ans += a*d
        a,d = 0,0
        flag = False s S[::-1] S ::-1 -1 if s=='D':
        if a>=1:
            ans += a*d
            a = 0
        d += 1
        flag = True
    elif s=='A':
        if flag:
            a += 1
    else:
        ans += a*d
        a,d = 0,0
        flag = False s=='D' s 'D' if a>=1:
            ans += a*d
            a = 0
         a>=1 a 1 ans += a*d ans a*d a d a = 0 a 0 d += 1 d 1 flag = True flag True elif s=='A':
        if flag:
            a += 1
     s=='A' s 'A' if flag:
            a += 1
     flag a += 1 a 1 ans += a*d ans a*d a d a,d = 0,0 a 0 d 0 flag = False flag False ans += a*d ans a*d a d print(ans) print ans d += 1 1 d a = 0 0 a d = 0,0 0 d def III(): return list(map(int, input().split())) def III(): return list(map(int, input().split())) III ans += a*d a*d ans def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

################# def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

################# Line flag = False False flag S = str(input()) str(input()) S ans = 0 0 ans def II(): return map(int, input().split()) def II(): return map(int, input().split()) II mod = 10**9 + 7 10**9 + 7 mod a,d = 0,0 0 a def input():
    return sys.stdin.readline()[:-1] def input():
    return sys.stdin.readline()[:-1] input ans += a*d a*d ans S = S.replace('BC', 'D') S.replace('BC', 'D') S flag = True True flag flag = False False flag def I(): return int(input()) def I(): return int(input()) I d = 0 0 d ans += a*d a*d ans a = 0 0 a a += 1 1 a
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

S = str(input())
S = S.replace('BC', 'D')

ans = 0
a = 0
d = 0
flag = False
for s in S[::-1]:
    if s=='D':
        if a>=1:
            ans += a*d
            a = 0
        d += 1
        flag = True
    elif s=='A':
        if flag:
            a += 1
    else:
        ans += a*d
        a,d = 0,0
        flag = False
ans += a*d

print(ans)