s=list(input())
s.append("D")
S=[]
i=0
while i<len(s):
  if s[i]=="A":
    S.append(1)
    i=i+1
  elif s[i]=="B":
    if s[i+1]=="C":
      S.append(2)
      i=i+2
    else:
      S.append(3)
      i=i+1
  else:
    S.append(3)
    i=i+1
ans=0
a=0
b=0
for i in range(len(S)):
  if S[i]==1:
    a=a+1
  elif S[i]==2:
    b=b+1
    ans=ans+a
  else:
    a=0
    b=0
print(ans) s=list(input()) s list(input()) list input() input s.append("D") s.append s append "D" S=[] S [] i=0 i 0 while i<len(s):
  if s[i]=="A":
    S.append(1)
    i=i+1
  elif s[i]=="B":
    if s[i+1]=="C":
      S.append(2)
      i=i+2
    else:
      S.append(3)
      i=i+1
  else:
    S.append(3)
    i=i+1 i<len(s) i len(s) len s if s[i]=="A":
    S.append(1)
    i=i+1
  elif s[i]=="B":
    if s[i+1]=="C":
      S.append(2)
      i=i+2
    else:
      S.append(3)
      i=i+1
  else:
    S.append(3)
    i=i+1 s[i]=="A" s[i] s i "A" S.append(1) S.append S append 1 i=i+1 i i+1 i 1 elif s[i]=="B":
    if s[i+1]=="C":
      S.append(2)
      i=i+2
    else:
      S.append(3)
      i=i+1
   s[i]=="B" s[i] s i "B" if s[i+1]=="C":
      S.append(2)
      i=i+2
    else:
      S.append(3)
      i=i+1
   s[i+1]=="C" s[i+1] s i+1 i 1 "C" S.append(2) S.append S append 2 i=i+2 i i+2 i 2 S.append(3) S.append S append 3 i=i+1 i i+1 i 1 S.append(3) S.append S append 3 i=i+1 i i+1 i 1 ans=0 ans 0 a=0 a 0 b=0 b 0 for i in range(len(S)):
  if S[i]==1:
    a=a+1
  elif S[i]==2:
    b=b+1
    ans=ans+a
  else:
    a=0
    b=0 i range(len(S)) range len(S) len S if S[i]==1:
    a=a+1
  elif S[i]==2:
    b=b+1
    ans=ans+a
  else:
    a=0
    b=0 S[i]==1 S[i] S i 1 a=a+1 a a+1 a 1 elif S[i]==2:
    b=b+1
    ans=ans+a
   S[i]==2 S[i] S i 2 b=b+1 b b+1 b 1 ans=ans+a ans ans+a ans a a=0 a 0 b=0 b 0 print(ans) print ans i=i+1 i+1 i i=i+1 i+1 i s=list(input()) list(input()) s b=0 0 b i=i+1 i+1 i ans=0 0 ans b=0 0 b ans=ans+a ans+a ans i=i+2 i+2 i i=0 0 i a=a+1 a+1 a a=0 0 a b=b+1 b+1 b S=[] [] S a=0 0 a
s=list(input())
s.append("D")
S=[]
i=0
while i<len(s):
  if s[i]=="A":
    S.append(1)
    i=i+1
  elif s[i]=="B":
    if s[i+1]=="C":
      S.append(2)
      i=i+2
    else:
      S.append(3)
      i=i+1
  else:
    S.append(3)
    i=i+1
ans=0
a=0
b=0
for i in range(len(S)):
  if S[i]==1:
    a=a+1
  elif S[i]==2:
    b=b+1
    ans=ans+a
  else:
    a=0
    b=0
print(ans)