s=input()

s2list=list(s.replace("BC","D"))
#print(s2list)

block_list=[]
bl=[]
for s2 in s2list:
  if s2=="A" or s2=="D":
    bl.append(s2)
  else:
    if len(bl)>0:
      block_list.append("".join(bl))
      bl=[]
else:
  if len(bl)>0:
    block_list.append("".join(bl))
#print(block_list)

answer=0
for bl in block_list:
  #print(bl)
  cnt_a=0
  for c in bl:
    if c=="A":
      cnt_a+=1
    else:
      answer+=cnt_a
    
print(answer) s=input() s input() input s2list=list(s.replace("BC","D")) s2list list(s.replace("BC","D")) list s.replace("BC","D") s.replace s replace "BC" "D" block_list=[] block_list [] bl=[] bl [] for s2 in s2list:
  if s2=="A" or s2=="D":
    bl.append(s2)
  else:
    if len(bl)>0:
      block_list.append("".join(bl))
      bl=[]
else:
  if len(bl)>0:
    block_list.append("".join(bl))
#print(block_list) s2 s2list if s2=="A" or s2=="D":
    bl.append(s2)
  else:
    if len(bl)>0:
      block_list.append("".join(bl))
      bl=[] s2=="A" or s2=="D" s2=="A" s2 "A" s2=="D" s2 "D" bl.append(s2) bl.append bl append s2 if len(bl)>0:
      block_list.append("".join(bl))
      bl=[] len(bl)>0 len(bl) len bl 0 block_list.append("".join(bl)) block_list.append block_list append "".join(bl) "".join "" join bl bl=[] bl [] if len(bl)>0:
    block_list.append("".join(bl))
#print(block_list) len(bl)>0 len(bl) len bl 0 block_list.append("".join(bl)) block_list.append block_list append "".join(bl) "".join "" join bl answer=0 answer 0 for bl in block_list:
  #print(bl)
  cnt_a=0
  for c in bl:
    if c=="A":
      cnt_a+=1
    else:
      answer+=cnt_a
     bl block_list cnt_a=0 cnt_a 0 for c in bl:
    if c=="A":
      cnt_a+=1
    else:
      answer+=cnt_a
     c bl if c=="A":
      cnt_a+=1
    else:
      answer+=cnt_a
     c=="A" c "A" cnt_a+=1 cnt_a 1 answer+=cnt_a answer cnt_a print(answer) print answer bl=[] [] bl cnt_a=0 0 cnt_a s=input() input() s cnt_a+=1 1 cnt_a s2list=list(s.replace("BC","D")) list(s.replace("BC","D")) s2list bl=[] [] bl answer=0 0 answer block_list=[] [] block_list answer+=cnt_a cnt_a answer
s=input()

s2list=list(s.replace("BC","D"))
#print(s2list)

block_list=[]
bl=[]
for s2 in s2list:
  if s2=="A" or s2=="D":
    bl.append(s2)
  else:
    if len(bl)>0:
      block_list.append("".join(bl))
      bl=[]
else:
  if len(bl)>0:
    block_list.append("".join(bl))
#print(block_list)

answer=0
for bl in block_list:
  #print(bl)
  cnt_a=0
  for c in bl:
    if c=="A":
      cnt_a+=1
    else:
      answer+=cnt_a
    
print(answer)