import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
n = len(s)
v = []
i = 0
tmp = []
while i<n:
    if s[i]=="A":
        tmp.append(0)
        i += 1
    elif i<n-1 and s[i]=="B" and s[i+1]=="C":
        tmp.append(1)
        i += 2
    else:
        i += 1
        if tmp:
            v.append(tmp)
        tmp = []
if tmp:
    v.append(tmp)
ans = 0
for l in v:
    val = 0
    for c in l:
        if c==1:
            ans += val
        else:
            val += 1
print(ans) import sys sys input = lambda : sys.stdin.readline().rstrip() input lambda : sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip sys.setrecursionlimit(max(1000, 10**9)) sys.setrecursionlimit sys setrecursionlimit max(1000, 10**9) max 1000 10**9 10 9 write = lambda x: sys.stdout.write(x+"\n") write lambda x: sys.stdout.write(x+"\n") sys.stdout.write(x+"\n") sys.stdout.write sys.stdout sys stdout write x+"\n" x "\n" x s = input() s input() input n = len(s) n len(s) len s v = [] v [] i = 0 i 0 tmp = [] tmp [] while i<n:
    if s[i]=="A":
        tmp.append(0)
        i += 1
    elif i<n-1 and s[i]=="B" and s[i+1]=="C":
        tmp.append(1)
        i += 2
    else:
        i += 1
        if tmp:
            v.append(tmp)
        tmp = [] i<n i n if s[i]=="A":
        tmp.append(0)
        i += 1
    elif i<n-1 and s[i]=="B" and s[i+1]=="C":
        tmp.append(1)
        i += 2
    else:
        i += 1
        if tmp:
            v.append(tmp)
        tmp = [] s[i]=="A" s[i] s i "A" tmp.append(0) tmp.append tmp append 0 i += 1 i 1 elif i<n-1 and s[i]=="B" and s[i+1]=="C":
        tmp.append(1)
        i += 2
     i<n-1 and s[i]=="B" and s[i+1]=="C" i<n-1 and s[i]=="B" i<n-1 i n-1 n 1 s[i]=="B" s[i] s i "B" s[i+1]=="C" s[i+1] s i+1 i 1 "C" tmp.append(1) tmp.append tmp append 1 i += 2 i 2 i += 1 i 1 if tmp:
            v.append(tmp)
         tmp v.append(tmp) v.append v append tmp tmp = [] tmp [] if tmp:
    v.append(tmp) tmp v.append(tmp) v.append v append tmp ans = 0 ans 0 for l in v:
    val = 0
    for c in l:
        if c==1:
            ans += val
        else:
            val += 1 l v val = 0 val 0 for c in l:
        if c==1:
            ans += val
        else:
            val += 1 c l if c==1:
            ans += val
        else:
            val += 1 c==1 c 1 ans += val ans val val += 1 val 1 print(ans) print ans val += 1 1 val input = lambda : sys.stdin.readline().rstrip() lambda : sys.stdin.readline().rstrip() input tmp = [] [] tmp i += 2 2 i ans = 0 0 ans i += 1 1 i write = lambda x: sys.stdout.write(x+"\n") lambda x: sys.stdout.write(x+"\n") write tmp = [] [] tmp n = len(s) len(s) n val = 0 0 val ans += val val ans i += 1 1 i s = input() input() s i = 0 0 i v = [] [] v
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
n = len(s)
v = []
i = 0
tmp = []
while i<n:
    if s[i]=="A":
        tmp.append(0)
        i += 1
    elif i<n-1 and s[i]=="B" and s[i+1]=="C":
        tmp.append(1)
        i += 2
    else:
        i += 1
        if tmp:
            v.append(tmp)
        tmp = []
if tmp:
    v.append(tmp)
ans = 0
for l in v:
    val = 0
    for c in l:
        if c==1:
            ans += val
        else:
            val += 1
print(ans)