s = input()
ans = 0

a_stack = 0
i = 0
while i < len(s):
    v = s[i]
    if v == 'A':
        a_stack += 1
        pass
    elif v == 'B' and i < len(s)-1 and s[i+1] == 'C':
        ans += a_stack
        i += 1
    else:
        a_stack = 0
    i+=1
print(ans) s = input() s input() input ans = 0 ans 0 a_stack = 0 a_stack 0 i = 0 i 0 while i < len(s):
    v = s[i]
    if v == 'A':
        a_stack += 1
        pass
    elif v == 'B' and i < len(s)-1 and s[i+1] == 'C':
        ans += a_stack
        i += 1
    else:
        a_stack = 0
    i+=1 i < len(s) i len(s) len s v = s[i] v s[i] s i if v == 'A':
        a_stack += 1
        pass
    elif v == 'B' and i < len(s)-1 and s[i+1] == 'C':
        ans += a_stack
        i += 1
    else:
        a_stack = 0
     v == 'A' v 'A' a_stack += 1 a_stack 1 elif v == 'B' and i < len(s)-1 and s[i+1] == 'C':
        ans += a_stack
        i += 1
     v == 'B' and i < len(s)-1 and s[i+1] == 'C' v == 'B' and i < len(s)-1 v == 'B' v 'B' i < len(s)-1 i len(s)-1 len(s) len s 1 s[i+1] == 'C' s[i+1] s i+1 i 1 'C' ans += a_stack ans a_stack i += 1 i 1 a_stack = 0 a_stack 0 i+=1 i 1 print(ans) print ans i = 0 0 i a_stack = 0 0 a_stack ans += a_stack a_stack ans i += 1 1 i s = input() input() s i+=1 1 i ans = 0 0 ans a_stack += 1 1 a_stack v = s[i] s[i] v a_stack = 0 0 a_stack
s = input()
ans = 0

a_stack = 0
i = 0
while i < len(s):
    v = s[i]
    if v == 'A':
        a_stack += 1
        pass
    elif v == 'B' and i < len(s)-1 and s[i+1] == 'C':
        ans += a_stack
        i += 1
    else:
        a_stack = 0
    i+=1
print(ans)
