# 解説
# ABC -> CBA
# BCは増えない&離れない
# AD -> DAを考える
# Aの右にBCが何個あるか

s = input()
n = len(s)
i = 0
ans = 0
count_a = 0

while i < n:
    if s[i] == 'A':
        count_a += 1
    elif i < n - 1 and s[i:i+2] == 'BC' and count_a > 0:
        ans += count_a
        i += 1
    else:
        count_a = 0
    i += 1
print(ans) s = input() s input() input n = len(s) n len(s) len s i = 0 i 0 ans = 0 ans 0 count_a = 0 count_a 0 while i < n:
    if s[i] == 'A':
        count_a += 1
    elif i < n - 1 and s[i:i+2] == 'BC' and count_a > 0:
        ans += count_a
        i += 1
    else:
        count_a = 0
    i += 1 i < n i n if s[i] == 'A':
        count_a += 1
    elif i < n - 1 and s[i:i+2] == 'BC' and count_a > 0:
        ans += count_a
        i += 1
    else:
        count_a = 0
     s[i] == 'A' s[i] s i 'A' count_a += 1 count_a 1 elif i < n - 1 and s[i:i+2] == 'BC' and count_a > 0:
        ans += count_a
        i += 1
     i < n - 1 and s[i:i+2] == 'BC' and count_a > 0 i < n - 1 and s[i:i+2] == 'BC' i < n - 1 i n - 1 n 1 s[i:i+2] == 'BC' s[i:i+2] s i:i+2 i i+2 i 2 'BC' count_a > 0 count_a 0 ans += count_a ans count_a i += 1 i 1 count_a = 0 count_a 0 i += 1 i 1 print(ans) print ans s = input() input() s i += 1 1 i count_a = 0 0 count_a count_a += 1 1 count_a count_a = 0 0 count_a ans = 0 0 ans ans += count_a count_a ans i += 1 1 i n = len(s) len(s) n i = 0 0 i
# 解説
# ABC -> CBA
# BCは増えない&離れない
# AD -> DAを考える
# Aの右にBCが何個あるか

s = input()
n = len(s)
i = 0
ans = 0
count_a = 0

while i < n:
    if s[i] == 'A':
        count_a += 1
    elif i < n - 1 and s[i:i+2] == 'BC' and count_a > 0:
        ans += count_a
        i += 1
    else:
        count_a = 0
    i += 1
print(ans)
