s=input()
s=s.replace("BC","D")
m=[]
is_seq=False
t=""
for ss in s:
  if is_seq:
    if ss=="A" or ss=="D":
      t+=ss
    else:
      m.append(t)
      t=""
      is_seq=False
  else:
    if ss=="A":
      is_seq=True
      t+=ss
if t!="":
  m.append(t) 
# print(m)
ans=0
for mm in m:
  cnt_a=mm.count("A")
  for i in range(len(mm)):
    if mm[i]=="A":
      ans+=len(mm)-cnt_a-i
      cnt_a-=1
print(ans)
 s=input() s input() input s=s.replace("BC","D") s s.replace("BC","D") s.replace s replace "BC" "D" m=[] m [] is_seq=False is_seq False t="" t "" for ss in s:
  if is_seq:
    if ss=="A" or ss=="D":
      t+=ss
    else:
      m.append(t)
      t=""
      is_seq=False
  else:
    if ss=="A":
      is_seq=True
      t+=ss ss s if is_seq:
    if ss=="A" or ss=="D":
      t+=ss
    else:
      m.append(t)
      t=""
      is_seq=False
  else:
    if ss=="A":
      is_seq=True
      t+=ss is_seq if ss=="A" or ss=="D":
      t+=ss
    else:
      m.append(t)
      t=""
      is_seq=False
   ss=="A" or ss=="D" ss=="A" ss "A" ss=="D" ss "D" t+=ss t ss m.append(t) m.append m append t t="" t "" is_seq=False is_seq False if ss=="A":
      is_seq=True
      t+=ss ss=="A" ss "A" is_seq=True is_seq True t+=ss t ss if t!="":
  m.append(t) 
# print(m) t!="" t "" m.append(t) m.append m append t ans=0 ans 0 for mm in m:
  cnt_a=mm.count("A")
  for i in range(len(mm)):
    if mm[i]=="A":
      ans+=len(mm)-cnt_a-i
      cnt_a-=1 mm m cnt_a=mm.count("A") cnt_a mm.count("A") mm.count mm count "A" for i in range(len(mm)):
    if mm[i]=="A":
      ans+=len(mm)-cnt_a-i
      cnt_a-=1 i range(len(mm)) range len(mm) len mm if mm[i]=="A":
      ans+=len(mm)-cnt_a-i
      cnt_a-=1 mm[i]=="A" mm[i] mm i "A" ans+=len(mm)-cnt_a-i ans len(mm)-cnt_a-i len(mm)-cnt_a len(mm) len mm cnt_a i cnt_a-=1 cnt_a 1 print(ans) print ans m=[] [] m cnt_a-=1 1 cnt_a ans+=len(mm)-cnt_a-i len(mm)-cnt_a-i ans is_seq=True True is_seq is_seq=False False is_seq ans=0 0 ans s=input() input() s s=s.replace("BC","D") s.replace("BC","D") s t+=ss ss t t="" "" t t+=ss ss t cnt_a=mm.count("A") mm.count("A") cnt_a t="" "" t is_seq=False False is_seq
s=input()
s=s.replace("BC","D")
m=[]
is_seq=False
t=""
for ss in s:
  if is_seq:
    if ss=="A" or ss=="D":
      t+=ss
    else:
      m.append(t)
      t=""
      is_seq=False
  else:
    if ss=="A":
      is_seq=True
      t+=ss
if t!="":
  m.append(t) 
# print(m)
ans=0
for mm in m:
  cnt_a=mm.count("A")
  for i in range(len(mm)):
    if mm[i]=="A":
      ans+=len(mm)-cnt_a-i
      cnt_a-=1
print(ans)

