s = input()

ss = s.replace('BC', '0').replace('A','1')

cnt = 0
ans = 0

for i in range(len(ss)-1, -1, -1):
    if ss[i] == 'B' or ss[i] == 'C':
        cnt = 0
    elif ss[i] == '1': ans += cnt
    else : cnt += 1
        
print(ans) s = input() s input() input ss = s.replace('BC', '0').replace('A','1') ss s.replace('BC', '0').replace('A','1') s.replace('BC', '0').replace s.replace('BC', '0') s.replace s replace 'BC' '0' replace 'A' '1' cnt = 0 cnt 0 ans = 0 ans 0 for i in range(len(ss)-1, -1, -1):
    if ss[i] == 'B' or ss[i] == 'C':
        cnt = 0
    elif ss[i] == '1': ans += cnt
    else : cnt += 1
         i range(len(ss)-1, -1, -1) range len(ss)-1 len(ss) len ss 1 -1 -1 if ss[i] == 'B' or ss[i] == 'C':
        cnt = 0
    elif ss[i] == '1': ans += cnt
    else : cnt += 1
         ss[i] == 'B' or ss[i] == 'C' ss[i] == 'B' ss[i] ss i 'B' ss[i] == 'C' ss[i] ss i 'C' cnt = 0 cnt 0 elif ss[i] == '1': ans += cnt
     ss[i] == '1' ss[i] ss i '1' print(ans) print ans ss = s.replace('BC', '0').replace('A','1') s.replace('BC', '0').replace('A','1') ss s = input() input() s ans = 0 0 ans cnt = 0 0 cnt cnt = 0 0 cnt
s = input()

ss = s.replace('BC', '0').replace('A','1')

cnt = 0
ans = 0

for i in range(len(ss)-1, -1, -1):
    if ss[i] == 'B' or ss[i] == 'C':
        cnt = 0
    elif ss[i] == '1': ans += cnt
    else : cnt += 1
        
print(ans)
