import sys
readline = sys.stdin.readline

S = readline().rstrip().replace("BC","X")

# AAXXX のようにAとXだけで構成されている部分は、
# Xを全て左に移動する
# BとCが残っている部分で切れる

parts = S.replace("B",",").replace("C",",").split(",")

ans = 0
for part in parts:
  # Xを探し、Xにあったら、そのときのインデックス - それまでにXを見つけた数する
  cnt = 0
  for i in range(len(part)):
    if part[i] == "X":
      ans += (i - cnt)
      cnt += 1

print(ans) import sys sys readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline S = readline().rstrip().replace("BC","X") S readline().rstrip().replace("BC","X") ().rstrip().replace ().rstrip() ().rstrip () readline rstrip replace "BC" "X" parts = S.replace("B",",").replace("C",",").split(",") parts S.replace("B",",").replace("C",",").split(",") S.replace("B",",").replace("C",",").split S.replace("B",",").replace("C",",") S.replace("B",",").replace S.replace("B",",") S.replace S replace "B" "," replace "C" "," split "," ans = 0 ans 0 for part in parts:
  # Xを探し、Xにあったら、そのときのインデックス - それまでにXを見つけた数する
  cnt = 0
  for i in range(len(part)):
    if part[i] == "X":
      ans += (i - cnt)
      cnt += 1 part parts cnt = 0 cnt 0 for i in range(len(part)):
    if part[i] == "X":
      ans += (i - cnt)
      cnt += 1 i range(len(part)) range len(part) len part if part[i] == "X":
      ans += (i - cnt)
      cnt += 1 part[i] == "X" part[i] part i "X" ans += (i - cnt) ans i - cnt i cnt cnt += 1 cnt 1 print(ans) print ans ans = 0 0 ans S = readline().rstrip().replace("BC","X") readline().rstrip().replace("BC","X") S parts = S.replace("B",",").replace("C",",").split(",") S.replace("B",",").replace("C",",").split(",") parts cnt = 0 0 cnt ans += (i - cnt) i - cnt ans cnt += 1 1 cnt readline = sys.stdin.readline sys.stdin.readline readline
import sys
readline = sys.stdin.readline

S = readline().rstrip().replace("BC","X")

# AAXXX のようにAとXだけで構成されている部分は、
# Xを全て左に移動する
# BとCが残っている部分で切れる

parts = S.replace("B",",").replace("C",",").split(",")

ans = 0
for part in parts:
  # Xを探し、Xにあったら、そのときのインデックス - それまでにXを見つけた数する
  cnt = 0
  for i in range(len(part)):
    if part[i] == "X":
      ans += (i - cnt)
      cnt += 1

print(ans)