S = input()

cnt = 0
ans = 0
n = 0
len_S = len(S)

while n < len_S:
  if S[n]== "A":
    cnt += 1
  elif S[n] == "B":
    if n < len_S-1:
      if S[n+1] == "C":
        ans += cnt
        n += 1
      else:
        cnt = 0
  else:
    cnt = 0
  n += 1
print(ans) S = input() S input() input cnt = 0 cnt 0 ans = 0 ans 0 n = 0 n 0 len_S = len(S) len_S len(S) len S while n < len_S:
  if S[n]== "A":
    cnt += 1
  elif S[n] == "B":
    if n < len_S-1:
      if S[n+1] == "C":
        ans += cnt
        n += 1
      else:
        cnt = 0
  else:
    cnt = 0
  n += 1 n < len_S n len_S if S[n]== "A":
    cnt += 1
  elif S[n] == "B":
    if n < len_S-1:
      if S[n+1] == "C":
        ans += cnt
        n += 1
      else:
        cnt = 0
  else:
    cnt = 0
   S[n]== "A" S[n] S n "A" cnt += 1 cnt 1 elif S[n] == "B":
    if n < len_S-1:
      if S[n+1] == "C":
        ans += cnt
        n += 1
      else:
        cnt = 0
   S[n] == "B" S[n] S n "B" if n < len_S-1:
      if S[n+1] == "C":
        ans += cnt
        n += 1
      else:
        cnt = 0
   n < len_S-1 n len_S-1 len_S 1 if S[n+1] == "C":
        ans += cnt
        n += 1
      else:
        cnt = 0
   S[n+1] == "C" S[n+1] S n+1 n 1 "C" ans += cnt ans cnt n += 1 n 1 cnt = 0 cnt 0 cnt = 0 cnt 0 n += 1 n 1 print(ans) print ans cnt += 1 1 cnt cnt = 0 0 cnt cnt = 0 0 cnt n += 1 1 n len_S = len(S) len(S) len_S ans = 0 0 ans n = 0 0 n cnt = 0 0 cnt n += 1 1 n ans += cnt cnt ans S = input() input() S
S = input()

cnt = 0
ans = 0
n = 0
len_S = len(S)

while n < len_S:
  if S[n]== "A":
    cnt += 1
  elif S[n] == "B":
    if n < len_S-1:
      if S[n+1] == "C":
        ans += cnt
        n += 1
      else:
        cnt = 0
  else:
    cnt = 0
  n += 1
print(ans)