S = input()
N = len(S)
S = S[:] + "X"
T = ""
i, j = 0, 0
X = 0
def excAB(n, lis):
  y = 0
  m = len(lis)
  for i in range(m):
    y += n - 1 - i - lis[m-1-i]
  return y

M = []
while i < N:
  if S[i] == 'A':
    T = T[:] + "A"
    i += 1
    M.append(j)
    j += 1
  elif S[i:i+2] == "BC":
    T = T[:] + "B"
    i += 2
    j += 1
  else:
    X += excAB(j, M)
    T = T[:] + "C"
    M = []
    i += 1
    j = 0
X += excAB(j, M)
print(X) S = input() S input() input N = len(S) N len(S) len S S = S[:] + "X" S S[:] + "X" S[:] S : "X" T = "" T "" i, j = 0, 0 i 0 j 0 X = 0 X 0 def excAB(n, lis):
  y = 0
  m = len(lis)
  for i in range(m):
    y += n - 1 - i - lis[m-1-i]
  return y excAB y = 0 y 0 m = len(lis) m len(lis) len lis for i in range(m):
    y += n - 1 - i - lis[m-1-i]
   i range(m) range m y += n - 1 - i - lis[m-1-i] y n - 1 - i - lis[m-1-i] n - 1 - i n - 1 n 1 i lis[m-1-i] lis m-1-i m-1 m 1 i return y y n n lis lis M = [] M [] while i < N:
  if S[i] == 'A':
    T = T[:] + "A"
    i += 1
    M.append(j)
    j += 1
  elif S[i:i+2] == "BC":
    T = T[:] + "B"
    i += 2
    j += 1
  else:
    X += excAB(j, M)
    T = T[:] + "C"
    M = []
    i += 1
    j = 0 i < N i N if S[i] == 'A':
    T = T[:] + "A"
    i += 1
    M.append(j)
    j += 1
  elif S[i:i+2] == "BC":
    T = T[:] + "B"
    i += 2
    j += 1
  else:
    X += excAB(j, M)
    T = T[:] + "C"
    M = []
    i += 1
    j = 0 S[i] == 'A' S[i] S i 'A' T = T[:] + "A" T T[:] + "A" T[:] T : "A" i += 1 i 1 M.append(j) M.append M append j j += 1 j 1 elif S[i:i+2] == "BC":
    T = T[:] + "B"
    i += 2
    j += 1
   S[i:i+2] == "BC" S[i:i+2] S i:i+2 i i+2 i 2 "BC" T = T[:] + "B" T T[:] + "B" T[:] T : "B" i += 2 i 2 j += 1 j 1 X += excAB(j, M) X excAB(j, M) excAB j M T = T[:] + "C" T T[:] + "C" T[:] T : "C" M = [] M [] i += 1 i 1 j = 0 j 0 X += excAB(j, M) X excAB(j, M) excAB j M print(X) print X M = [] [] M i += 1 1 i N = len(S) len(S) N S = S[:] + "X" S[:] + "X" S M = [] [] M X += excAB(j, M) excAB(j, M) X X = 0 0 X T = T[:] + "A" T[:] + "A" T j += 1 1 j def excAB(n, lis):
  y = 0
  m = len(lis)
  for i in range(m):
    y += n - 1 - i - lis[m-1-i]
  return y def excAB(n, lis):
  y = 0
  m = len(lis)
  for i in range(m):
    y += n - 1 - i - lis[m-1-i]
  return y excAB j = 0, 0 0 j j = 0 0 j j += 1 1 j S = input() input() S T = "" "" T i += 2 2 i i, j = 0, 0 0 i T = T[:] + "C" T[:] + "C" T i += 1 1 i T = T[:] + "B" T[:] + "B" T X += excAB(j, M) excAB(j, M) X
S = input()
N = len(S)
S = S[:] + "X"
T = ""
i, j = 0, 0
X = 0
def excAB(n, lis):
  y = 0
  m = len(lis)
  for i in range(m):
    y += n - 1 - i - lis[m-1-i]
  return y

M = []
while i < N:
  if S[i] == 'A':
    T = T[:] + "A"
    i += 1
    M.append(j)
    j += 1
  elif S[i:i+2] == "BC":
    T = T[:] + "B"
    i += 2
    j += 1
  else:
    X += excAB(j, M)
    T = T[:] + "C"
    M = []
    i += 1
    j = 0
X += excAB(j, M)
print(X)