S=input().replace("BC","D").split("B")
T=[]
for t in S:
    for u in t.split("C"):
        T.append(u)
#print(T)
ans=0
for s in T:
    n=len(s)
    k=0
    for i in range(n):
        if s[i]=="D":
            ans+=(i-k)
            k+=1
print(ans) S=input().replace("BC","D").split("B") S input().replace("BC","D").split("B") ().replace("BC","D").split ().replace("BC","D") ().replace () input replace "BC" "D" split "B" T=[] T [] for t in S:
    for u in t.split("C"):
        T.append(u)
#print(T) t S for u in t.split("C"):
        T.append(u)
#print(T) u t.split("C") t.split t split "C" T.append(u) T.append T append u ans=0 ans 0 for s in T:
    n=len(s)
    k=0
    for i in range(n):
        if s[i]=="D":
            ans+=(i-k)
            k+=1 s T n=len(s) n len(s) len s k=0 k 0 for i in range(n):
        if s[i]=="D":
            ans+=(i-k)
            k+=1 i range(n) range n if s[i]=="D":
            ans+=(i-k)
            k+=1 s[i]=="D" s[i] s i "D" ans+=(i-k) ans i-k i k k+=1 k 1 print(ans) print ans k=0 0 k S=input().replace("BC","D").split("B") input().replace("BC","D").split("B") S ans+=(i-k) i-k ans k+=1 1 k ans=0 0 ans n=len(s) len(s) n T=[] [] T
S=input().replace("BC","D").split("B")
T=[]
for t in S:
    for u in t.split("C"):
        T.append(u)
#print(T)
ans=0
for s in T:
    n=len(s)
    k=0
    for i in range(n):
        if s[i]=="D":
            ans+=(i-k)
            k+=1
print(ans)