import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

s = input()
n = len(s)
ans = 0
p = 0
cnt_a = 0
while True:
    while p<n and s[p] == 'A':
        cnt_a += 1
        p += 1
    
    while p<n-1 and s[p] == 'B' and s[p+1] == 'C':
        ans += cnt_a
        p+=2
    while p<n and s[p] == 'C':
        p+=1
        cnt_a = 0
    while p<n and s[p] == 'B':
        p+=1
        cnt_a=0
    
    if p>=n:
        break
print(ans) import os os import sys sys from atexit import register from io import BytesIO sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size)) sys.stdin sys stdin BytesIO(os.read(0, os.fstat(0).st_size)) BytesIO os.read(0, os.fstat(0).st_size) os.read os read 0 os.fstat(0).st_size os.fstat(0) os.fstat os fstat 0 st_size sys.stdout = BytesIO() sys.stdout sys stdout BytesIO() BytesIO register(lambda: os.write(1, sys.stdout.getvalue())) register lambda: os.write(1, sys.stdout.getvalue()) os.write(1, sys.stdout.getvalue()) os.write os write 1 sys.stdout.getvalue() sys.stdout.getvalue sys.stdout sys stdout getvalue input = lambda: sys.stdin.readline().rstrip('\r\n') input lambda: sys.stdin.readline().rstrip('\r\n') sys.stdin.readline().rstrip('\r\n') sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip '\r\n' raw_input = lambda: sys.stdin.readline().rstrip('\r\n') raw_input lambda: sys.stdin.readline().rstrip('\r\n') sys.stdin.readline().rstrip('\r\n') sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip '\r\n' s = input() s input() input n = len(s) n len(s) len s ans = 0 ans 0 p = 0 p 0 cnt_a = 0 cnt_a 0 while True:
    while p<n and s[p] == 'A':
        cnt_a += 1
        p += 1
    
    while p<n-1 and s[p] == 'B' and s[p+1] == 'C':
        ans += cnt_a
        p+=2
    while p<n and s[p] == 'C':
        p+=1
        cnt_a = 0
    while p<n and s[p] == 'B':
        p+=1
        cnt_a=0
    
    if p>=n:
        break True while p<n and s[p] == 'A':
        cnt_a += 1
        p += 1
    
     p<n and s[p] == 'A' p<n p n s[p] == 'A' s[p] s p 'A' cnt_a += 1 cnt_a 1 p += 1 p 1 while p<n-1 and s[p] == 'B' and s[p+1] == 'C':
        ans += cnt_a
        p+=2
     p<n-1 and s[p] == 'B' and s[p+1] == 'C' p<n-1 and s[p] == 'B' p<n-1 p n-1 n 1 s[p] == 'B' s[p] s p 'B' s[p+1] == 'C' s[p+1] s p+1 p 1 'C' ans += cnt_a ans cnt_a p+=2 p 2 while p<n and s[p] == 'C':
        p+=1
        cnt_a = 0
     p<n and s[p] == 'C' p<n p n s[p] == 'C' s[p] s p 'C' p+=1 p 1 cnt_a = 0 cnt_a 0 while p<n and s[p] == 'B':
        p+=1
        cnt_a=0
    
     p<n and s[p] == 'B' p<n p n s[p] == 'B' s[p] s p 'B' p+=1 p 1 cnt_a=0 cnt_a 0 if p>=n:
        break p>=n p n break print(ans) print ans p+=2 2 p cnt_a = 0 0 cnt_a input = lambda: sys.stdin.readline().rstrip('\r\n') lambda: sys.stdin.readline().rstrip('\r\n') input ans = 0 0 ans cnt_a += 1 1 cnt_a s = input() input() s ans += cnt_a cnt_a ans n = len(s) len(s) n p += 1 1 p p+=1 1 p raw_input = lambda: sys.stdin.readline().rstrip('\r\n') lambda: sys.stdin.readline().rstrip('\r\n') raw_input p = 0 0 p cnt_a = 0 0 cnt_a p+=1 1 p cnt_a=0 0 cnt_a
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

s = input()
n = len(s)
ans = 0
p = 0
cnt_a = 0
while True:
    while p<n and s[p] == 'A':
        cnt_a += 1
        p += 1
    
    while p<n-1 and s[p] == 'B' and s[p+1] == 'C':
        ans += cnt_a
        p+=2
    while p<n and s[p] == 'C':
        p+=1
        cnt_a = 0
    while p<n and s[p] == 'B':
        p+=1
        cnt_a=0
    
    if p>=n:
        break
print(ans)