S = input()
ans = 0
idx = 0
a_count = 0
while idx < len(S):
    if S[idx] == "A":
        a_count += 1
    elif S[idx:idx+2] == "BC":
        ans += a_count
        idx += 1
    else:
        a_count = 0
    idx += 1
print(ans) S = input() S input() input ans = 0 ans 0 idx = 0 idx 0 a_count = 0 a_count 0 while idx < len(S):
    if S[idx] == "A":
        a_count += 1
    elif S[idx:idx+2] == "BC":
        ans += a_count
        idx += 1
    else:
        a_count = 0
    idx += 1 idx < len(S) idx len(S) len S if S[idx] == "A":
        a_count += 1
    elif S[idx:idx+2] == "BC":
        ans += a_count
        idx += 1
    else:
        a_count = 0
     S[idx] == "A" S[idx] S idx "A" a_count += 1 a_count 1 elif S[idx:idx+2] == "BC":
        ans += a_count
        idx += 1
     S[idx:idx+2] == "BC" S[idx:idx+2] S idx:idx+2 idx idx+2 idx 2 "BC" ans += a_count ans a_count idx += 1 idx 1 a_count = 0 a_count 0 idx += 1 idx 1 print(ans) print ans a_count = 0 0 a_count a_count += 1 1 a_count S = input() input() S idx += 1 1 idx ans = 0 0 ans idx = 0 0 idx ans += a_count a_count ans idx += 1 1 idx a_count = 0 0 a_count
S = input()
ans = 0
idx = 0
a_count = 0
while idx < len(S):
    if S[idx] == "A":
        a_count += 1
    elif S[idx:idx+2] == "BC":
        ans += a_count
        idx += 1
    else:
        a_count = 0
    idx += 1
print(ans)