s = input()
cnt = 0
flg = 0
ans = 0
for i in range(len(s)-1):
  if s[i] == "A":
    if flg == 0:
      cnt += 1
    else:
      cnt = 1
  elif s[i:i+2] == "BC":
    ans += cnt
    flg = 1
  elif flg == 1:
    flg = 0
    continue
  else:
    cnt = 0
print(ans) s = input() s input() input cnt = 0 cnt 0 flg = 0 flg 0 ans = 0 ans 0 for i in range(len(s)-1):
  if s[i] == "A":
    if flg == 0:
      cnt += 1
    else:
      cnt = 1
  elif s[i:i+2] == "BC":
    ans += cnt
    flg = 1
  elif flg == 1:
    flg = 0
    continue
  else:
    cnt = 0 i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i] == "A":
    if flg == 0:
      cnt += 1
    else:
      cnt = 1
  elif s[i:i+2] == "BC":
    ans += cnt
    flg = 1
  elif flg == 1:
    flg = 0
    continue
  else:
    cnt = 0 s[i] == "A" s[i] s i "A" if flg == 0:
      cnt += 1
    else:
      cnt = 1
   flg == 0 flg 0 cnt += 1 cnt 1 cnt = 1 cnt 1 elif s[i:i+2] == "BC":
    ans += cnt
    flg = 1
   s[i:i+2] == "BC" s[i:i+2] s i:i+2 i i+2 i 2 "BC" ans += cnt ans cnt flg = 1 flg 1 elif flg == 1:
    flg = 0
    continue
   flg == 1 flg 1 flg = 0 flg 0 continue cnt = 0 cnt 0 print(ans) print ans flg = 1 1 flg ans = 0 0 ans cnt = 0 0 cnt flg = 0 0 flg cnt = 0 0 cnt ans += cnt cnt ans s = input() input() s flg = 0 0 flg cnt += 1 1 cnt cnt = 1 1 cnt
s = input()
cnt = 0
flg = 0
ans = 0
for i in range(len(s)-1):
  if s[i] == "A":
    if flg == 0:
      cnt += 1
    else:
      cnt = 1
  elif s[i:i+2] == "BC":
    ans += cnt
    flg = 1
  elif flg == 1:
    flg = 0
    continue
  else:
    cnt = 0
print(ans)