s=input()
ans=0
bc=0
i=len(s)-1
while i>=0:
  if s[i]=="A":
    ans+=bc
    i-=1
  elif i>0 and s[i-1:i+1]=="BC":
    bc+=1
    i-=2
  else:
    bc=0
    i-=1
print(ans) s=input() s input() input ans=0 ans 0 bc=0 bc 0 i=len(s)-1 i len(s)-1 len(s) len s 1 while i>=0:
  if s[i]=="A":
    ans+=bc
    i-=1
  elif i>0 and s[i-1:i+1]=="BC":
    bc+=1
    i-=2
  else:
    bc=0
    i-=1 i>=0 i 0 if s[i]=="A":
    ans+=bc
    i-=1
  elif i>0 and s[i-1:i+1]=="BC":
    bc+=1
    i-=2
  else:
    bc=0
    i-=1 s[i]=="A" s[i] s i "A" ans+=bc ans bc i-=1 i 1 elif i>0 and s[i-1:i+1]=="BC":
    bc+=1
    i-=2
   i>0 and s[i-1:i+1]=="BC" i>0 i 0 s[i-1:i+1]=="BC" s[i-1:i+1] s i-1:i+1 i-1 i 1 i+1 i 1 "BC" bc+=1 bc 1 i-=2 i 2 bc=0 bc 0 i-=1 i 1 print(ans) print ans bc=0 0 bc bc+=1 1 bc i=len(s)-1 len(s)-1 i i-=1 1 i i-=1 1 i i-=2 2 i bc=0 0 bc ans=0 0 ans s=input() input() s ans+=bc bc ans
s=input()
ans=0
bc=0
i=len(s)-1
while i>=0:
  if s[i]=="A":
    ans+=bc
    i-=1
  elif i>0 and s[i-1:i+1]=="BC":
    bc+=1
    i-=2
  else:
    bc=0
    i-=1
print(ans)