#!/usr/bin/env python3
from itertools import accumulate

s = input()
l = s.split('BC')[:-1]
l = l[::-1]

ans = 0
i = 0

while i < len(l):
    anum = []
    flag = True
    while flag and i < len(l):
        M = len(l[i])
        tmp = 0
        for j in range(M):
            if l[i][M-j-1] == 'A':
                tmp += 1
            else:
                flag = False
                break
        anum.append(tmp)
        if flag:
            i += 1
    ans += sum(accumulate(anum[::-1]))
    i += 1
print(ans) from itertools import accumulate s = input() s input() input l = s.split('BC')[:-1] l s.split('BC')[:-1] s.split('BC') s.split s split 'BC' :-1 -1 l = l[::-1] l l[::-1] l ::-1 -1 ans = 0 ans 0 i = 0 i 0 while i < len(l):
    anum = []
    flag = True
    while flag and i < len(l):
        M = len(l[i])
        tmp = 0
        for j in range(M):
            if l[i][M-j-1] == 'A':
                tmp += 1
            else:
                flag = False
                break
        anum.append(tmp)
        if flag:
            i += 1
    ans += sum(accumulate(anum[::-1]))
    i += 1 i < len(l) i len(l) len l anum = [] anum [] flag = True flag True while flag and i < len(l):
        M = len(l[i])
        tmp = 0
        for j in range(M):
            if l[i][M-j-1] == 'A':
                tmp += 1
            else:
                flag = False
                break
        anum.append(tmp)
        if flag:
            i += 1
     flag and i < len(l) flag i < len(l) i len(l) len l M = len(l[i]) M len(l[i]) len l[i] l i tmp = 0 tmp 0 for j in range(M):
            if l[i][M-j-1] == 'A':
                tmp += 1
            else:
                flag = False
                break
         j range(M) range M if l[i][M-j-1] == 'A':
                tmp += 1
            else:
                flag = False
                break
         l[i][M-j-1] == 'A' l[i][M-j-1] [i] l i M-j-1 M-j M j 1 'A' tmp += 1 tmp 1 flag = False flag False break anum.append(tmp) anum.append anum append tmp if flag:
            i += 1
     flag i += 1 i 1 ans += sum(accumulate(anum[::-1])) ans sum(accumulate(anum[::-1])) sum accumulate(anum[::-1]) accumulate anum[::-1] anum ::-1 -1 i += 1 i 1 print(ans) print ans i = 0 0 i tmp += 1 1 tmp flag = False False flag M = len(l[i]) len(l[i]) M l = l[::-1] l[::-1] l ans += sum(accumulate(anum[::-1])) sum(accumulate(anum[::-1])) ans ans = 0 0 ans s = input() input() s tmp = 0 0 tmp i += 1 1 i i += 1 1 i anum = [] [] anum flag = True True flag l = s.split('BC')[:-1] s.split('BC')[:-1] l
#!/usr/bin/env python3
from itertools import accumulate

s = input()
l = s.split('BC')[:-1]
l = l[::-1]

ans = 0
i = 0

while i < len(l):
    anum = []
    flag = True
    while flag and i < len(l):
        M = len(l[i])
        tmp = 0
        for j in range(M):
            if l[i][M-j-1] == 'A':
                tmp += 1
            else:
                flag = False
                break
        anum.append(tmp)
        if flag:
            i += 1
    ans += sum(accumulate(anum[::-1]))
    i += 1
print(ans)
