s=input()
s=s.replace("BC", "D")
ans=0
a=0
for c in s:
    if c=='A': a+=1
    elif c=='D': ans+=a
    else: a=0
print(ans) s=input() s input() input s=s.replace("BC", "D") s s.replace("BC", "D") s.replace s replace "BC" "D" ans=0 ans 0 a=0 a 0 for c in s:
    if c=='A': a+=1
    elif c=='D': ans+=a
    else: a=0 c s if c=='A': a+=1
    elif c=='D': ans+=a
    else: a=0 c=='A' c 'A' elif c=='D': ans+=a
     c=='D' c 'D' print(ans) print ans s=s.replace("BC", "D") s.replace("BC", "D") s ans=0 0 ans a=0 0 a s=input() input() s
s=input()
s=s.replace("BC", "D")
ans=0
a=0
for c in s:
    if c=='A': a+=1
    elif c=='D': ans+=a
    else: a=0
print(ans)