S = input()
ABD = S.replace("BC","D")
a_cnt = 0
ans = 0
# print(ABD)
# print(S)
for s in ABD:
    if s == 'A':
        a_cnt += 1
    elif s == 'D':
        ans += a_cnt
    elif s == 'B' or s == 'C':
        a_cnt = 0
print(ans) S = input() S input() input ABD = S.replace("BC","D") ABD S.replace("BC","D") S.replace S replace "BC" "D" a_cnt = 0 a_cnt 0 ans = 0 ans 0 for s in ABD:
    if s == 'A':
        a_cnt += 1
    elif s == 'D':
        ans += a_cnt
    elif s == 'B' or s == 'C':
        a_cnt = 0 s ABD if s == 'A':
        a_cnt += 1
    elif s == 'D':
        ans += a_cnt
    elif s == 'B' or s == 'C':
        a_cnt = 0 s == 'A' s 'A' a_cnt += 1 a_cnt 1 elif s == 'D':
        ans += a_cnt
     s == 'D' s 'D' ans += a_cnt ans a_cnt elif s == 'B' or s == 'C':
        a_cnt = 0 s == 'B' or s == 'C' s == 'B' s 'B' s == 'C' s 'C' a_cnt = 0 a_cnt 0 print(ans) print ans a_cnt = 0 0 a_cnt S = input() input() S ans = 0 0 ans ABD = S.replace("BC","D") S.replace("BC","D") ABD a_cnt += 1 1 a_cnt ans += a_cnt a_cnt ans a_cnt = 0 0 a_cnt
S = input()
ABD = S.replace("BC","D")
a_cnt = 0
ans = 0
# print(ABD)
# print(S)
for s in ABD:
    if s == 'A':
        a_cnt += 1
    elif s == 'D':
        ans += a_cnt
    elif s == 'B' or s == 'C':
        a_cnt = 0
print(ans)