s=input()
s=s.replace("BC","D")
s=s.replace("B","E")
s=s.replace("C","E")
s=s.split("E")

t=[]
for ss in s:
  if len(ss)!=0:
    t.append(ss)
ans=0

for tt in t:
  d_cnt=0
  for i,ttt in enumerate(tt):
    if ttt=="D":
      ans+=i-d_cnt
      d_cnt+=1
print(ans) s=input() s input() input s=s.replace("BC","D") s s.replace("BC","D") s.replace s replace "BC" "D" s=s.replace("B","E") s s.replace("B","E") s.replace s replace "B" "E" s=s.replace("C","E") s s.replace("C","E") s.replace s replace "C" "E" s=s.split("E") s s.split("E") s.split s split "E" t=[] t [] for ss in s:
  if len(ss)!=0:
    t.append(ss) ss s if len(ss)!=0:
    t.append(ss) len(ss)!=0 len(ss) len ss 0 t.append(ss) t.append t append ss ans=0 ans 0 for tt in t:
  d_cnt=0
  for i,ttt in enumerate(tt):
    if ttt=="D":
      ans+=i-d_cnt
      d_cnt+=1 tt t d_cnt=0 d_cnt 0 for i,ttt in enumerate(tt):
    if ttt=="D":
      ans+=i-d_cnt
      d_cnt+=1 i ttt enumerate(tt) enumerate tt if ttt=="D":
      ans+=i-d_cnt
      d_cnt+=1 ttt=="D" ttt "D" ans+=i-d_cnt ans i-d_cnt i d_cnt d_cnt+=1 d_cnt 1 print(ans) print ans d_cnt=0 0 d_cnt d_cnt+=1 1 d_cnt s=s.replace("BC","D") s.replace("BC","D") s s=s.replace("C","E") s.replace("C","E") s t=[] [] t s=s.replace("B","E") s.replace("B","E") s ans+=i-d_cnt i-d_cnt ans s=input() input() s s=s.split("E") s.split("E") s ans=0 0 ans
s=input()
s=s.replace("BC","D")
s=s.replace("B","E")
s=s.replace("C","E")
s=s.split("E")

t=[]
for ss in s:
  if len(ss)!=0:
    t.append(ss)
ans=0

for tt in t:
  d_cnt=0
  for i,ttt in enumerate(tt):
    if ttt=="D":
      ans+=i-d_cnt
      d_cnt+=1
print(ans)