def main():
  S = str(input())
  s = []
  i = 0
  while i <= len(S)-1:
    if i == len(S)-1:
      s.append(S[i])
      break
    if S[i] == "B" and S[i+1] == "C":
      s.append("D")
      i += 2
    else:
      s.append(S[i])
      i += 1
  ans = 0
  flag = True
  for i in range(len(s)-1, -1, -1):
    if flag and s[i] == "D":
      posi = i
      flag = False
    if not flag and s[i]=="A":
      ans += posi-i
      posi-= 1
    if s[i] == "B" or s[i] == "C":
      flag = True
  print(ans)
  
  
if __name__ == "__main__":
  main() def main():
  S = str(input())
  s = []
  i = 0
  while i <= len(S)-1:
    if i == len(S)-1:
      s.append(S[i])
      break
    if S[i] == "B" and S[i+1] == "C":
      s.append("D")
      i += 2
    else:
      s.append(S[i])
      i += 1
  ans = 0
  flag = True
  for i in range(len(s)-1, -1, -1):
    if flag and s[i] == "D":
      posi = i
      flag = False
    if not flag and s[i]=="A":
      ans += posi-i
      posi-= 1
    if s[i] == "B" or s[i] == "C":
      flag = True
  print(ans)
  
   main S = str(input()) S str(input()) str input() input s = [] s [] i = 0 i 0 while i <= len(S)-1:
    if i == len(S)-1:
      s.append(S[i])
      break
    if S[i] == "B" and S[i+1] == "C":
      s.append("D")
      i += 2
    else:
      s.append(S[i])
      i += 1
   i <= len(S)-1 i len(S)-1 len(S) len S 1 if i == len(S)-1:
      s.append(S[i])
      break
     i == len(S)-1 i len(S)-1 len(S) len S 1 s.append(S[i]) s.append s append S[i] S i break if S[i] == "B" and S[i+1] == "C":
      s.append("D")
      i += 2
    else:
      s.append(S[i])
      i += 1
   S[i] == "B" and S[i+1] == "C" S[i] == "B" S[i] S i "B" S[i+1] == "C" S[i+1] S i+1 i 1 "C" s.append("D") s.append s append "D" i += 2 i 2 s.append(S[i]) s.append s append S[i] S i i += 1 i 1 ans = 0 ans 0 flag = True flag True for i in range(len(s)-1, -1, -1):
    if flag and s[i] == "D":
      posi = i
      flag = False
    if not flag and s[i]=="A":
      ans += posi-i
      posi-= 1
    if s[i] == "B" or s[i] == "C":
      flag = True
   i range(len(s)-1, -1, -1) range len(s)-1 len(s) len s 1 -1 -1 if flag and s[i] == "D":
      posi = i
      flag = False
     flag and s[i] == "D" flag s[i] == "D" s[i] s i "D" posi = i posi i flag = False flag False if not flag and s[i]=="A":
      ans += posi-i
      posi-= 1
     not flag and s[i]=="A" not flag flag s[i]=="A" s[i] s i "A" ans += posi-i ans posi-i posi i posi-= 1 posi 1 if s[i] == "B" or s[i] == "C":
      flag = True
   s[i] == "B" or s[i] == "C" s[i] == "B" s[i] s i "B" s[i] == "C" s[i] s i "C" flag = True flag True print(ans) print ans if __name__ == "__main__":
  main() __name__ == "__main__" __name__ "__main__" main() main def main():
  S = str(input())
  s = []
  i = 0
  while i <= len(S)-1:
    if i == len(S)-1:
      s.append(S[i])
      break
    if S[i] == "B" and S[i+1] == "C":
      s.append("D")
      i += 2
    else:
      s.append(S[i])
      i += 1
  ans = 0
  flag = True
  for i in range(len(s)-1, -1, -1):
    if flag and s[i] == "D":
      posi = i
      flag = False
    if not flag and s[i]=="A":
      ans += posi-i
      posi-= 1
    if s[i] == "B" or s[i] == "C":
      flag = True
  print(ans)
  
   def main():
  S = str(input())
  s = []
  i = 0
  while i <= len(S)-1:
    if i == len(S)-1:
      s.append(S[i])
      break
    if S[i] == "B" and S[i+1] == "C":
      s.append("D")
      i += 2
    else:
      s.append(S[i])
      i += 1
  ans = 0
  flag = True
  for i in range(len(s)-1, -1, -1):
    if flag and s[i] == "D":
      posi = i
      flag = False
    if not flag and s[i]=="A":
      ans += posi-i
      posi-= 1
    if s[i] == "B" or s[i] == "C":
      flag = True
  print(ans)
  
   main
def main():
  S = str(input())
  s = []
  i = 0
  while i <= len(S)-1:
    if i == len(S)-1:
      s.append(S[i])
      break
    if S[i] == "B" and S[i+1] == "C":
      s.append("D")
      i += 2
    else:
      s.append(S[i])
      i += 1
  ans = 0
  flag = True
  for i in range(len(s)-1, -1, -1):
    if flag and s[i] == "D":
      posi = i
      flag = False
    if not flag and s[i]=="A":
      ans += posi-i
      posi-= 1
    if s[i] == "B" or s[i] == "C":
      flag = True
  print(ans)
  
  
if __name__ == "__main__":
  main()