a=input()
a=a.replace("BC","X")
a=a[::-1]
X_c=0
ans=0
for i in range(len(a)):
   if a[i]=="X":
      X_c+=1
   elif a[i]=="A":
      ans+=X_c
   else:
      X_c=0
print(ans) a=input() a input() input a=a.replace("BC","X") a a.replace("BC","X") a.replace a replace "BC" "X" a=a[::-1] a a[::-1] a ::-1 -1 X_c=0 X_c 0 ans=0 ans 0 for i in range(len(a)):
   if a[i]=="X":
      X_c+=1
   elif a[i]=="A":
      ans+=X_c
   else:
      X_c=0 i range(len(a)) range len(a) len a if a[i]=="X":
      X_c+=1
   elif a[i]=="A":
      ans+=X_c
   else:
      X_c=0 a[i]=="X" a[i] a i "X" X_c+=1 X_c 1 elif a[i]=="A":
      ans+=X_c
    a[i]=="A" a[i] a i "A" ans+=X_c ans X_c X_c=0 X_c 0 print(ans) print ans X_c=0 0 X_c ans=0 0 ans a=a.replace("BC","X") a.replace("BC","X") a X_c=0 0 X_c a=a[::-1] a[::-1] a ans+=X_c X_c ans a=input() input() a X_c+=1 1 X_c
a=input()
a=a.replace("BC","X")
a=a[::-1]
X_c=0
ans=0
for i in range(len(a)):
   if a[i]=="X":
      X_c+=1
   elif a[i]=="A":
      ans+=X_c
   else:
      X_c=0
print(ans)