S=list(input())

nS=[]
i=0
while i<len(S)-1:
  if S[i]=="B" and S[i+1]=="C":
    nS.append("D")
    i+=1
  else:
    nS.append(S[i])
  i+=1
    
t=[]
nl=[]
for i in nS:
  if i=="A" or i=="D":
    nl.append(i)
  else:
    if nl:
      t.append(nl)
      nl=[]
if nl:
  t.append(nl)


ans=0
for i in t:
  dn=0
  for j in range(len(i)):
    if i[j]=="D":
      ans+=j-dn
      dn+=1

print(ans) S=list(input()) S list(input()) list input() input nS=[] nS [] i=0 i 0 while i<len(S)-1:
  if S[i]=="B" and S[i+1]=="C":
    nS.append("D")
    i+=1
  else:
    nS.append(S[i])
  i+=1
     i<len(S)-1 i len(S)-1 len(S) len S 1 if S[i]=="B" and S[i+1]=="C":
    nS.append("D")
    i+=1
  else:
    nS.append(S[i])
   S[i]=="B" and S[i+1]=="C" S[i]=="B" S[i] S i "B" S[i+1]=="C" S[i+1] S i+1 i 1 "C" nS.append("D") nS.append nS append "D" i+=1 i 1 nS.append(S[i]) nS.append nS append S[i] S i i+=1 i 1 t=[] t [] nl=[] nl [] for i in nS:
  if i=="A" or i=="D":
    nl.append(i)
  else:
    if nl:
      t.append(nl)
      nl=[] i nS if i=="A" or i=="D":
    nl.append(i)
  else:
    if nl:
      t.append(nl)
      nl=[] i=="A" or i=="D" i=="A" i "A" i=="D" i "D" nl.append(i) nl.append nl append i if nl:
      t.append(nl)
      nl=[] nl t.append(nl) t.append t append nl nl=[] nl [] if nl:
  t.append(nl) nl t.append(nl) t.append t append nl ans=0 ans 0 for i in t:
  dn=0
  for j in range(len(i)):
    if i[j]=="D":
      ans+=j-dn
      dn+=1 i t dn=0 dn 0 for j in range(len(i)):
    if i[j]=="D":
      ans+=j-dn
      dn+=1 j range(len(i)) range len(i) len i if i[j]=="D":
      ans+=j-dn
      dn+=1 i[j]=="D" i[j] i j "D" ans+=j-dn ans j-dn j dn dn+=1 dn 1 print(ans) print ans nS=[] [] nS nl=[] [] nl ans=0 0 ans i=0 0 i t=[] [] t dn=0 0 dn i+=1 1 i nl=[] [] nl i+=1 1 i dn+=1 1 dn S=list(input()) list(input()) S ans+=j-dn j-dn ans
S=list(input())

nS=[]
i=0
while i<len(S)-1:
  if S[i]=="B" and S[i+1]=="C":
    nS.append("D")
    i+=1
  else:
    nS.append(S[i])
  i+=1
    
t=[]
nl=[]
for i in nS:
  if i=="A" or i=="D":
    nl.append(i)
  else:
    if nl:
      t.append(nl)
      nl=[]
if nl:
  t.append(nl)


ans=0
for i in t:
  dn=0
  for j in range(len(i)):
    if i[j]=="D":
      ans+=j-dn
      dn+=1

print(ans)
