s = input()
n = len(s)
d = [s[0]]
for i in range(1,n):
  if s[i]=="C" and s[i-1]=='B':
    d.pop()
    d.append("x")
  else:
    d.append(s[i])
q = "".join(d)
cou = 0
cou_a = 0
l = len(q)
for i in range(l):
  if q[i]=="A":
    cou_a += 1
  elif q[i]=="x":
    cou +=  cou_a
  else:
    cou_a = 0
print(cou) s = input() s input() input n = len(s) n len(s) len s d = [s[0]] d [s[0]] s[0] s 0 for i in range(1,n):
  if s[i]=="C" and s[i-1]=='B':
    d.pop()
    d.append("x")
  else:
    d.append(s[i]) i range(1,n) range 1 n if s[i]=="C" and s[i-1]=='B':
    d.pop()
    d.append("x")
  else:
    d.append(s[i]) s[i]=="C" and s[i-1]=='B' s[i]=="C" s[i] s i "C" s[i-1]=='B' s[i-1] s i-1 i 1 'B' d.pop() d.pop d pop d.append("x") d.append d append "x" d.append(s[i]) d.append d append s[i] s i q = "".join(d) q "".join(d) "".join "" join d cou = 0 cou 0 cou_a = 0 cou_a 0 l = len(q) l len(q) len q for i in range(l):
  if q[i]=="A":
    cou_a += 1
  elif q[i]=="x":
    cou +=  cou_a
  else:
    cou_a = 0 i range(l) range l if q[i]=="A":
    cou_a += 1
  elif q[i]=="x":
    cou +=  cou_a
  else:
    cou_a = 0 q[i]=="A" q[i] q i "A" cou_a += 1 cou_a 1 elif q[i]=="x":
    cou +=  cou_a
   q[i]=="x" q[i] q i "x" cou +=  cou_a cou cou_a cou_a = 0 cou_a 0 print(cou) print cou cou +=  cou_a cou_a cou n = len(s) len(s) n cou_a = 0 0 cou_a cou_a += 1 1 cou_a cou_a = 0 0 cou_a q = "".join(d) "".join(d) q l = len(q) len(q) l d = [s[0]] [s[0]] d cou = 0 0 cou s = input() input() s
s = input()
n = len(s)
d = [s[0]]
for i in range(1,n):
  if s[i]=="C" and s[i-1]=='B':
    d.pop()
    d.append("x")
  else:
    d.append(s[i])
q = "".join(d)
cou = 0
cou_a = 0
l = len(q)
for i in range(l):
  if q[i]=="A":
    cou_a += 1
  elif q[i]=="x":
    cou +=  cou_a
  else:
    cou_a = 0
print(cou)