import sys
input = sys.stdin.readline
S = list(input())[: -1]
t = []
res = 0
i = 1
while i < len(S):
  if S[i - 1] == "B" and (S[i] == "C"):
    t.append("X")
    i += 1
  else:
    if S[i - 1] == "A": t.append(S[i - 1])
    else: t.append("Y")
  i += 1
tt = "".join(t).split("Y")
for x in tt:
  xs = x.count("X")
  for i in range(len(x)):
    if x[i] == "A":
      res += xs
    else: xs -= 1
print(res) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline S = list(input())[: -1] S list(input())[: -1] (input()) list input() input : -1 -1 t = [] t [] res = 0 res 0 i = 1 i 1 while i < len(S):
  if S[i - 1] == "B" and (S[i] == "C"):
    t.append("X")
    i += 1
  else:
    if S[i - 1] == "A": t.append(S[i - 1])
    else: t.append("Y")
  i += 1 i < len(S) i len(S) len S if S[i - 1] == "B" and (S[i] == "C"):
    t.append("X")
    i += 1
  else:
    if S[i - 1] == "A": t.append(S[i - 1])
    else: t.append("Y")
   S[i - 1] == "B" and (S[i] == "C") S[i - 1] == "B" S[i - 1] S i - 1 i 1 "B" S[i] == "C" S[i] S i "C" t.append("X") t.append t append "X" i += 1 i 1 if S[i - 1] == "A": t.append(S[i - 1])
    else: t.append("Y")
   S[i - 1] == "A" S[i - 1] S i - 1 i 1 "A" i += 1 i 1 tt = "".join(t).split("Y") tt "".join(t).split("Y") "".join(t).split "".join(t) "".join "" join t split "Y" for x in tt:
  xs = x.count("X")
  for i in range(len(x)):
    if x[i] == "A":
      res += xs
    else: xs -= 1 x tt xs = x.count("X") xs x.count("X") x.count x count "X" for i in range(len(x)):
    if x[i] == "A":
      res += xs
    else: xs -= 1 i range(len(x)) range len(x) len x if x[i] == "A":
      res += xs
    else: xs -= 1 x[i] == "A" x[i] x i "A" res += xs res xs print(res) print res res = 0 0 res tt = "".join(t).split("Y") "".join(t).split("Y") tt i += 1 1 i res += xs xs res input = sys.stdin.readline sys.stdin.readline input t = [] [] t i = 1 1 i S = list(input())[: -1] list(input())[: -1] S xs = x.count("X") x.count("X") xs i += 1 1 i
import sys
input = sys.stdin.readline
S = list(input())[: -1]
t = []
res = 0
i = 1
while i < len(S):
  if S[i - 1] == "B" and (S[i] == "C"):
    t.append("X")
    i += 1
  else:
    if S[i - 1] == "A": t.append(S[i - 1])
    else: t.append("Y")
  i += 1
tt = "".join(t).split("Y")
for x in tt:
  xs = x.count("X")
  for i in range(len(x)):
    if x[i] == "A":
      res += xs
    else: xs -= 1
print(res)