S = input()
N = len(S)
X = []
x = 0
while x<N-1:
    if S[x]=="B" and S[x+1]=="C":
        X.append("D")
        x+=1
    else:
        X.append(S[x])
    x+=1
ans = 0
N = len(X)
a = 0
for i in range(N):
    if X[i]=="A":
        a+=1
    elif X[i]=="D":
        ans+=a
    else:
        a=0
print(ans) S = input() S input() input N = len(S) N len(S) len S X = [] X [] x = 0 x 0 while x<N-1:
    if S[x]=="B" and S[x+1]=="C":
        X.append("D")
        x+=1
    else:
        X.append(S[x])
    x+=1 x<N-1 x N-1 N 1 if S[x]=="B" and S[x+1]=="C":
        X.append("D")
        x+=1
    else:
        X.append(S[x])
     S[x]=="B" and S[x+1]=="C" S[x]=="B" S[x] S x "B" S[x+1]=="C" S[x+1] S x+1 x 1 "C" X.append("D") X.append X append "D" x+=1 x 1 X.append(S[x]) X.append X append S[x] S x x+=1 x 1 ans = 0 ans 0 N = len(X) N len(X) len X a = 0 a 0 for i in range(N):
    if X[i]=="A":
        a+=1
    elif X[i]=="D":
        ans+=a
    else:
        a=0 i range(N) range N if X[i]=="A":
        a+=1
    elif X[i]=="D":
        ans+=a
    else:
        a=0 X[i]=="A" X[i] X i "A" a+=1 a 1 elif X[i]=="D":
        ans+=a
     X[i]=="D" X[i] X i "D" ans+=a ans a a=0 a 0 print(ans) print ans x+=1 1 x S = input() input() S X = [] [] X N = len(X) len(X) N x = 0 0 x x+=1 1 x ans = 0 0 ans a=0 0 a N = len(S) len(S) N ans+=a a ans a = 0 0 a a+=1 1 a
S = input()
N = len(S)
X = []
x = 0
while x<N-1:
    if S[x]=="B" and S[x+1]=="C":
        X.append("D")
        x+=1
    else:
        X.append(S[x])
    x+=1
ans = 0
N = len(X)
a = 0
for i in range(N):
    if X[i]=="A":
        a+=1
    elif X[i]=="D":
        ans+=a
    else:
        a=0
print(ans)