s=input()
s=s.replace("BC","D")
s=s.replace("B"," ")
s=s.replace("C"," ")
s=list(s.split())
ans=0
for u in s:
    if u:
        u=list(u)
        count=0
        cnt=0
        for i in range(len(u)):
            if u[i]=="D":
                count+=i
                cnt+=1
        ans+=count-cnt*(cnt-1)//2
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"," ") s s.replace("B"," ") s.replace s replace "B" " " s=s.replace("C"," ") s s.replace("C"," ") s.replace s replace "C" " " s=list(s.split()) s list(s.split()) list s.split() s.split s split ans=0 ans 0 for u in s:
    if u:
        u=list(u)
        count=0
        cnt=0
        for i in range(len(u)):
            if u[i]=="D":
                count+=i
                cnt+=1
        ans+=count-cnt*(cnt-1)//2 u s if u:
        u=list(u)
        count=0
        cnt=0
        for i in range(len(u)):
            if u[i]=="D":
                count+=i
                cnt+=1
        ans+=count-cnt*(cnt-1)//2 u u=list(u) u list(u) list u count=0 count 0 cnt=0 cnt 0 for i in range(len(u)):
            if u[i]=="D":
                count+=i
                cnt+=1
         i range(len(u)) range len(u) len u if u[i]=="D":
                count+=i
                cnt+=1
         u[i]=="D" u[i] u i "D" count+=i count i cnt+=1 cnt 1 ans+=count-cnt*(cnt-1)//2 ans count-cnt*(cnt-1)//2 count cnt*(cnt-1)//2 cnt*(cnt-1) cnt cnt-1 cnt 1 2 print(ans) print ans count=0 0 count s=s.replace("BC","D") s.replace("BC","D") s s=list(s.split()) list(s.split()) s u=list(u) list(u) u count+=i i count s=input() input() s ans+=count-cnt*(cnt-1)//2 count-cnt*(cnt-1)//2 ans ans=0 0 ans s=s.replace("C"," ") s.replace("C"," ") s s=s.replace("B"," ") s.replace("B"," ") s cnt+=1 1 cnt cnt=0 0 cnt
s=input()
s=s.replace("BC","D")
s=s.replace("B"," ")
s=s.replace("C"," ")
s=list(s.split())
ans=0
for u in s:
    if u:
        u=list(u)
        count=0
        cnt=0
        for i in range(len(u)):
            if u[i]=="D":
                count+=i
                cnt+=1
        ans+=count-cnt*(cnt-1)//2
print(ans)