w=input()
count=0
num=len(w)
w1=""
w+=" "
while count<num:
  if w[count]=="A":
    w1+="A"
    count+=1
  elif w[count]=="B":
    if w[count+1]=="C":
      w1+="D"
      count+=2
    else:
      w1+="B"
      count+=1
  else:
    w1+="C"
    count+=1
counta=0
ans=0
num=len(w1)
for i in range(num):
  if w1[i]=="A":
    counta+=1
  elif w1[i]=="D":
    ans+=counta
  else:
    counta=0
print(ans) w=input() w input() input count=0 count 0 num=len(w) num len(w) len w w1="" w1 "" w+=" " w " " while count<num:
  if w[count]=="A":
    w1+="A"
    count+=1
  elif w[count]=="B":
    if w[count+1]=="C":
      w1+="D"
      count+=2
    else:
      w1+="B"
      count+=1
  else:
    w1+="C"
    count+=1 count<num count num if w[count]=="A":
    w1+="A"
    count+=1
  elif w[count]=="B":
    if w[count+1]=="C":
      w1+="D"
      count+=2
    else:
      w1+="B"
      count+=1
  else:
    w1+="C"
    count+=1 w[count]=="A" w[count] w count "A" w1+="A" w1 "A" count+=1 count 1 elif w[count]=="B":
    if w[count+1]=="C":
      w1+="D"
      count+=2
    else:
      w1+="B"
      count+=1
   w[count]=="B" w[count] w count "B" if w[count+1]=="C":
      w1+="D"
      count+=2
    else:
      w1+="B"
      count+=1
   w[count+1]=="C" w[count+1] w count+1 count 1 "C" w1+="D" w1 "D" count+=2 count 2 w1+="B" w1 "B" count+=1 count 1 w1+="C" w1 "C" count+=1 count 1 counta=0 counta 0 ans=0 ans 0 num=len(w1) num len(w1) len w1 for i in range(num):
  if w1[i]=="A":
    counta+=1
  elif w1[i]=="D":
    ans+=counta
  else:
    counta=0 i range(num) range num if w1[i]=="A":
    counta+=1
  elif w1[i]=="D":
    ans+=counta
  else:
    counta=0 w1[i]=="A" w1[i] w1 i "A" counta+=1 counta 1 elif w1[i]=="D":
    ans+=counta
   w1[i]=="D" w1[i] w1 i "D" ans+=counta ans counta counta=0 counta 0 print(ans) print ans num=len(w1) len(w1) num count+=1 1 count w+=" " " " w w1+="C" "C" w1 count+=1 1 count counta=0 0 counta ans+=counta counta ans counta=0 0 counta w1+="A" "A" w1 w1+="B" "B" w1 w=input() input() w num=len(w) len(w) num ans=0 0 ans counta+=1 1 counta count=0 0 count w1="" "" w1 w1+="D" "D" w1 count+=1 1 count count+=2 2 count
w=input()
count=0
num=len(w)
w1=""
w+=" "
while count<num:
  if w[count]=="A":
    w1+="A"
    count+=1
  elif w[count]=="B":
    if w[count+1]=="C":
      w1+="D"
      count+=2
    else:
      w1+="B"
      count+=1
  else:
    w1+="C"
    count+=1
counta=0
ans=0
num=len(w1)
for i in range(num):
  if w1[i]=="A":
    counta+=1
  elif w1[i]=="D":
    ans+=counta
  else:
    counta=0
print(ans)