S = input()
N = len(S)
ans = 0
cnt = 0
i = 0
while i < N:
  if S[i] == "A":
    cnt += 1
    i += 1
  elif "".join(S[i:i+2]) == "BC":
    ans += cnt
    i += 2
  else:
    cnt = 0
    i += 1
print(ans) S = input() S input() input N = len(S) N len(S) len S ans = 0 ans 0 cnt = 0 cnt 0 i = 0 i 0 while i < N:
  if S[i] == "A":
    cnt += 1
    i += 1
  elif "".join(S[i:i+2]) == "BC":
    ans += cnt
    i += 2
  else:
    cnt = 0
    i += 1 i < N i N if S[i] == "A":
    cnt += 1
    i += 1
  elif "".join(S[i:i+2]) == "BC":
    ans += cnt
    i += 2
  else:
    cnt = 0
    i += 1 S[i] == "A" S[i] S i "A" cnt += 1 cnt 1 i += 1 i 1 elif "".join(S[i:i+2]) == "BC":
    ans += cnt
    i += 2
   "".join(S[i:i+2]) == "BC" "".join(S[i:i+2]) "".join "" join S[i:i+2] S i:i+2 i i+2 i 2 "BC" ans += cnt ans cnt i += 2 i 2 cnt = 0 cnt 0 i += 1 i 1 print(ans) print ans S = input() input() S cnt += 1 1 cnt N = len(S) len(S) N i += 1 1 i i = 0 0 i ans += cnt cnt ans cnt = 0 0 cnt i += 1 1 i cnt = 0 0 cnt i += 2 2 i ans = 0 0 ans
S = input()
N = len(S)
ans = 0
cnt = 0
i = 0
while i < N:
  if S[i] == "A":
    cnt += 1
    i += 1
  elif "".join(S[i:i+2]) == "BC":
    ans += cnt
    i += 2
  else:
    cnt = 0
    i += 1
print(ans)