S = input()
S = S.replace('BC', 'D')
S = S.replace('B', 'C')
S = S.split('C')
ans = 0

def count_inv(s):
  res = num = 0
  for si in s:
    if si == 'A':
      num += 1
    else:
      res += num
  return res


for s in S:
  ans += count_inv(s)
  
print(ans) 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' S = S.split('C') S S.split('C') S.split S split 'C' ans = 0 ans 0 def count_inv(s):
  res = num = 0
  for si in s:
    if si == 'A':
      num += 1
    else:
      res += num
  return res count_inv res = num = 0 res 0 = num = 0 num 0 for si in s:
    if si == 'A':
      num += 1
    else:
      res += num
   si s if si == 'A':
      num += 1
    else:
      res += num
   si == 'A' si 'A' num += 1 num 1 res += num res num return res res s s for s in S:
  ans += count_inv(s)
   s S ans += count_inv(s) ans count_inv(s) count_inv s print(ans) print ans S = S.replace('BC', 'D') S.replace('BC', 'D') S S = S.replace('B', 'C') S.replace('B', 'C') S S = S.split('C') S.split('C') S ans += count_inv(s) count_inv(s) ans ans = 0 0 ans S = input() input() S def count_inv(s):
  res = num = 0
  for si in s:
    if si == 'A':
      num += 1
    else:
      res += num
  return res def count_inv(s):
  res = num = 0
  for si in s:
    if si == 'A':
      num += 1
    else:
      res += num
  return res count_inv
S = input()
S = S.replace('BC', 'D')
S = S.replace('B', 'C')
S = S.split('C')
ans = 0

def count_inv(s):
  res = num = 0
  for si in s:
    if si == 'A':
      num += 1
    else:
      res += num
  return res


for s in S:
  ans += count_inv(s)
  
print(ans)