def sol(S):
  N = len(S)
  nums = [0 for _ in range(N+1)]
  i = N-1
  while i >= 0:
    if S[i-1:i+1] == 'BC':
      nums[i-1] = nums[i+1] + 1
      nums[i] = nums[i+1] + 1
      i -= 2
    else:
      nums[i] = nums[i+1]
      i -= 1
  ans = 0
  for i, s in enumerate(S):
    if s == 'A':
      ans += nums[i]
  return ans

S = input()
ans = 0
N = len(S)
si, i = 0, 0
while i < N:
  if S[i] == 'A':
    i += 1
  elif S[i:i+2] == 'BC':
    i += 2
  else:
    ans += sol(S[si:i+1])
    si = i + 1
    i += 1
ans += sol(S[si:])
print(ans) def sol(S):
  N = len(S)
  nums = [0 for _ in range(N+1)]
  i = N-1
  while i >= 0:
    if S[i-1:i+1] == 'BC':
      nums[i-1] = nums[i+1] + 1
      nums[i] = nums[i+1] + 1
      i -= 2
    else:
      nums[i] = nums[i+1]
      i -= 1
  ans = 0
  for i, s in enumerate(S):
    if s == 'A':
      ans += nums[i]
  return ans sol N = len(S) N len(S) len S 0 for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) 0 nums = [0 for _ in range(N+1)] nums [0 for _ in range(N+1)] i = N-1 i N-1 N 1 while i >= 0:
    if S[i-1:i+1] == 'BC':
      nums[i-1] = nums[i+1] + 1
      nums[i] = nums[i+1] + 1
      i -= 2
    else:
      nums[i] = nums[i+1]
      i -= 1
   i >= 0 i 0 if S[i-1:i+1] == 'BC':
      nums[i-1] = nums[i+1] + 1
      nums[i] = nums[i+1] + 1
      i -= 2
    else:
      nums[i] = nums[i+1]
      i -= 1
   S[i-1:i+1] == 'BC' S[i-1:i+1] S i-1:i+1 i-1 i 1 i+1 i 1 'BC' nums[i-1] = nums[i+1] + 1 nums[i-1] nums i-1 i 1 nums[i+1] + 1 nums[i+1] nums i+1 i 1 1 nums[i] = nums[i+1] + 1 nums[i] nums i nums[i+1] + 1 nums[i+1] nums i+1 i 1 1 i -= 2 i 2 nums[i] = nums[i+1] nums[i] nums i nums[i+1] nums i+1 i 1 i -= 1 i 1 ans = 0 ans 0 for i, s in enumerate(S):
    if s == 'A':
      ans += nums[i]
   i s enumerate(S) enumerate S if s == 'A':
      ans += nums[i]
   s == 'A' s 'A' ans += nums[i] ans nums[i] nums i return ans ans S S S = input() S input() input ans = 0 ans 0 N = len(S) N len(S) len S si, i = 0, 0 si 0 i 0 while i < N:
  if S[i] == 'A':
    i += 1
  elif S[i:i+2] == 'BC':
    i += 2
  else:
    ans += sol(S[si:i+1])
    si = i + 1
    i += 1 i < N i N if S[i] == 'A':
    i += 1
  elif S[i:i+2] == 'BC':
    i += 2
  else:
    ans += sol(S[si:i+1])
    si = i + 1
    i += 1 S[i] == 'A' S[i] S i 'A' i += 1 i 1 elif S[i:i+2] == 'BC':
    i += 2
   S[i:i+2] == 'BC' S[i:i+2] S i:i+2 i i+2 i 2 'BC' i += 2 i 2 ans += sol(S[si:i+1]) ans sol(S[si:i+1]) sol S[si:i+1] S si:i+1 si i+1 i 1 si = i + 1 si i + 1 i 1 i += 1 i 1 ans += sol(S[si:]) ans sol(S[si:]) sol S[si:] S si: si print(ans) print ans def sol(S):
  N = len(S)
  nums = [0 for _ in range(N+1)]
  i = N-1
  while i >= 0:
    if S[i-1:i+1] == 'BC':
      nums[i-1] = nums[i+1] + 1
      nums[i] = nums[i+1] + 1
      i -= 2
    else:
      nums[i] = nums[i+1]
      i -= 1
  ans = 0
  for i, s in enumerate(S):
    if s == 'A':
      ans += nums[i]
  return ans def sol(S):
  N = len(S)
  nums = [0 for _ in range(N+1)]
  i = N-1
  while i >= 0:
    if S[i-1:i+1] == 'BC':
      nums[i-1] = nums[i+1] + 1
      nums[i] = nums[i+1] + 1
      i -= 2
    else:
      nums[i] = nums[i+1]
      i -= 1
  ans = 0
  for i, s in enumerate(S):
    if s == 'A':
      ans += nums[i]
  return ans sol ans = 0 0 ans si = i + 1 i + 1 si ans += sol(S[si:]) sol(S[si:]) ans i = 0, 0 0 i si, i = 0, 0 0 si ans += sol(S[si:i+1]) sol(S[si:i+1]) ans i += 2 2 i i += 1 1 i i += 1 1 i S = input() input() S N = len(S) len(S) N
def sol(S):
  N = len(S)
  nums = [0 for _ in range(N+1)]
  i = N-1
  while i >= 0:
    if S[i-1:i+1] == 'BC':
      nums[i-1] = nums[i+1] + 1
      nums[i] = nums[i+1] + 1
      i -= 2
    else:
      nums[i] = nums[i+1]
      i -= 1
  ans = 0
  for i, s in enumerate(S):
    if s == 'A':
      ans += nums[i]
  return ans

S = input()
ans = 0
N = len(S)
si, i = 0, 0
while i < N:
  if S[i] == 'A':
    i += 1
  elif S[i:i+2] == 'BC':
    i += 2
  else:
    ans += sol(S[si:i+1])
    si = i + 1
    i += 1
ans += sol(S[si:])
print(ans)