#ABCがBCAになる
#ADがDAになる
s = input()
s = s.replace("BC", "D")

c_A = 0
ans = 0
for v in s:
  if v == "A":
    c_A += 1
  elif v == "D":
    ans += c_A
  else:
    c_A = 0
print(ans) s = input() s input() input s = s.replace("BC", "D") s s.replace("BC", "D") s.replace s replace "BC" "D" c_A = 0 c_A 0 ans = 0 ans 0 for v in s:
  if v == "A":
    c_A += 1
  elif v == "D":
    ans += c_A
  else:
    c_A = 0 v s if v == "A":
    c_A += 1
  elif v == "D":
    ans += c_A
  else:
    c_A = 0 v == "A" v "A" c_A += 1 c_A 1 elif v == "D":
    ans += c_A
   v == "D" v "D" ans += c_A ans c_A c_A = 0 c_A 0 print(ans) print ans c_A += 1 1 c_A s = input() input() s c_A = 0 0 c_A s = s.replace("BC", "D") s.replace("BC", "D") s c_A = 0 0 c_A ans = 0 0 ans ans += c_A c_A ans
#ABCがBCAになる
#ADがDAになる
s = input()
s = s.replace("BC", "D")

c_A = 0
ans = 0
for v in s:
  if v == "A":
    c_A += 1
  elif v == "D":
    ans += c_A
  else:
    c_A = 0
print(ans)