def resolve():
  s = input()
  s = s.replace('BC', 'D')
  s = s.replace('B', 'C')

  ans = 0
  count = 0
  for c in s:
    if c == 'C':
      count = 0
      continue
    if c == 'A':
      count += 1
    if c == 'D':
      ans += count

  print(ans)


if __name__ == "__main__":
  resolve() def resolve():
  s = input()
  s = s.replace('BC', 'D')
  s = s.replace('B', 'C')

  ans = 0
  count = 0
  for c in s:
    if c == 'C':
      count = 0
      continue
    if c == 'A':
      count += 1
    if c == 'D':
      ans += count

  print(ans) resolve s = input() s input() input s = s.replace('BC', 'D') s s.replace('BC', 'D') s.replace s replace 'BC' 'D' s = s.replace('B', 'C') s s.replace('B', 'C') s.replace s replace 'B' 'C' ans = 0 ans 0 count = 0 count 0 for c in s:
    if c == 'C':
      count = 0
      continue
    if c == 'A':
      count += 1
    if c == 'D':
      ans += count

   c s if c == 'C':
      count = 0
      continue
     c == 'C' c 'C' count = 0 count 0 continue if c == 'A':
      count += 1
     c == 'A' c 'A' count += 1 count 1 if c == 'D':
      ans += count

   c == 'D' c 'D' ans += count ans count print(ans) print ans if __name__ == "__main__":
  resolve() __name__ == "__main__" __name__ "__main__" resolve() resolve def resolve():
  s = input()
  s = s.replace('BC', 'D')
  s = s.replace('B', 'C')

  ans = 0
  count = 0
  for c in s:
    if c == 'C':
      count = 0
      continue
    if c == 'A':
      count += 1
    if c == 'D':
      ans += count

  print(ans) def resolve():
  s = input()
  s = s.replace('BC', 'D')
  s = s.replace('B', 'C')

  ans = 0
  count = 0
  for c in s:
    if c == 'C':
      count = 0
      continue
    if c == 'A':
      count += 1
    if c == 'D':
      ans += count

  print(ans) resolve
def resolve():
  s = input()
  s = s.replace('BC', 'D')
  s = s.replace('B', 'C')

  ans = 0
  count = 0
  for c in s:
    if c == 'C':
      count = 0
      continue
    if c == 'A':
      count += 1
    if c == 'D':
      ans += count

  print(ans)


if __name__ == "__main__":
  resolve()
