s=input()
i=1
new=[s[0]]
while i<len(s):
    if s[i]=="C" and s[i-1] == "B":
        new.pop()
        new.append("K")
    else:
        new.append(s[i])
    i+=1

cnt=0
ans=0
for i in range(len(new)-1,-1,-1):
    if new[i]=="A" and cnt > 0:
        ans+=cnt
    elif new[i]=="K":
        cnt+=1
    else:
        cnt=0
    
print(ans) s=input() s input() input i=1 i 1 new=[s[0]] new [s[0]] s[0] s 0 while i<len(s):
    if s[i]=="C" and s[i-1] == "B":
        new.pop()
        new.append("K")
    else:
        new.append(s[i])
    i+=1 i<len(s) i len(s) len s if s[i]=="C" and s[i-1] == "B":
        new.pop()
        new.append("K")
    else:
        new.append(s[i])
     s[i]=="C" and s[i-1] == "B" s[i]=="C" s[i] s i "C" s[i-1] == "B" s[i-1] s i-1 i 1 "B" new.pop() new.pop new pop new.append("K") new.append new append "K" new.append(s[i]) new.append new append s[i] s i i+=1 i 1 cnt=0 cnt 0 ans=0 ans 0 for i in range(len(new)-1,-1,-1):
    if new[i]=="A" and cnt > 0:
        ans+=cnt
    elif new[i]=="K":
        cnt+=1
    else:
        cnt=0
     i range(len(new)-1,-1,-1) range len(new)-1 len(new) len new 1 -1 -1 if new[i]=="A" and cnt > 0:
        ans+=cnt
    elif new[i]=="K":
        cnt+=1
    else:
        cnt=0
     new[i]=="A" and cnt > 0 new[i]=="A" new[i] new i "A" cnt > 0 cnt 0 ans+=cnt ans cnt elif new[i]=="K":
        cnt+=1
     new[i]=="K" new[i] new i "K" cnt+=1 cnt 1 cnt=0 cnt 0 print(ans) print ans ans=0 0 ans new=[s[0]] [s[0]] new cnt=0 0 cnt cnt+=1 1 cnt cnt=0 0 cnt ans+=cnt cnt ans i=1 1 i i+=1 1 i s=input() input() s
s=input()
i=1
new=[s[0]]
while i<len(s):
    if s[i]=="C" and s[i-1] == "B":
        new.pop()
        new.append("K")
    else:
        new.append(s[i])
    i+=1

cnt=0
ans=0
for i in range(len(new)-1,-1,-1):
    if new[i]=="A" and cnt > 0:
        ans+=cnt
    elif new[i]=="K":
        cnt+=1
    else:
        cnt=0
    
print(ans)