S = input()
S = S.replace("BC", "D")

S = list(S)

cnt1 = 0
cnt2 = 0
ans = 0
for i in range(len(S)):
    if S[i] == "A":
        cnt1 += 1
    elif S[i] == "D":
        cnt2 += 1
        ans += cnt1
    else:
        cnt1 = 0
        cnt2 = 0
print(ans) S = input() S input() input S = S.replace("BC", "D") S S.replace("BC", "D") S.replace S replace "BC" "D" S = list(S) S list(S) list S cnt1 = 0 cnt1 0 cnt2 = 0 cnt2 0 ans = 0 ans 0 for i in range(len(S)):
    if S[i] == "A":
        cnt1 += 1
    elif S[i] == "D":
        cnt2 += 1
        ans += cnt1
    else:
        cnt1 = 0
        cnt2 = 0 i range(len(S)) range len(S) len S if S[i] == "A":
        cnt1 += 1
    elif S[i] == "D":
        cnt2 += 1
        ans += cnt1
    else:
        cnt1 = 0
        cnt2 = 0 S[i] == "A" S[i] S i "A" cnt1 += 1 cnt1 1 elif S[i] == "D":
        cnt2 += 1
        ans += cnt1
     S[i] == "D" S[i] S i "D" cnt2 += 1 cnt2 1 ans += cnt1 ans cnt1 cnt1 = 0 cnt1 0 cnt2 = 0 cnt2 0 print(ans) print ans S = S.replace("BC", "D") S.replace("BC", "D") S cnt2 = 0 0 cnt2 S = input() input() S ans += cnt1 cnt1 ans ans = 0 0 ans cnt1 = 0 0 cnt1 cnt2 += 1 1 cnt2 cnt1 += 1 1 cnt1 cnt2 = 0 0 cnt2 S = list(S) list(S) S cnt1 = 0 0 cnt1
S = input()
S = S.replace("BC", "D")

S = list(S)

cnt1 = 0
cnt2 = 0
ans = 0
for i in range(len(S)):
    if S[i] == "A":
        cnt1 += 1
    elif S[i] == "D":
        cnt2 += 1
        ans += cnt1
    else:
        cnt1 = 0
        cnt2 = 0
print(ans)
