s=input()
n=len(s)
i,a,ans=0,0,0
while i<n:
    if s[i]=="A":
        a+=1
        i+=1
    elif i<n-1 and s[i:i+2]=="BC":
        ans+=a
        i+=2
        while i<n:
            if s[i]=="A":
                a+=1
                i+=1
            elif i<n-1 and s[i:i+2]=="BC":
                ans+=a
                i+=2
            else:
                a=0
                i+=1
                break
    else:
        i+=1
        a=0
print(ans) s=input() s input() input n=len(s) n len(s) len s i,a,ans=0,0,0 i 0 a 0 ans 0 while i<n:
    if s[i]=="A":
        a+=1
        i+=1
    elif i<n-1 and s[i:i+2]=="BC":
        ans+=a
        i+=2
        while i<n:
            if s[i]=="A":
                a+=1
                i+=1
            elif i<n-1 and s[i:i+2]=="BC":
                ans+=a
                i+=2
            else:
                a=0
                i+=1
                break
    else:
        i+=1
        a=0 i<n i n if s[i]=="A":
        a+=1
        i+=1
    elif i<n-1 and s[i:i+2]=="BC":
        ans+=a
        i+=2
        while i<n:
            if s[i]=="A":
                a+=1
                i+=1
            elif i<n-1 and s[i:i+2]=="BC":
                ans+=a
                i+=2
            else:
                a=0
                i+=1
                break
    else:
        i+=1
        a=0 s[i]=="A" s[i] s i "A" a+=1 a 1 i+=1 i 1 elif i<n-1 and s[i:i+2]=="BC":
        ans+=a
        i+=2
        while i<n:
            if s[i]=="A":
                a+=1
                i+=1
            elif i<n-1 and s[i:i+2]=="BC":
                ans+=a
                i+=2
            else:
                a=0
                i+=1
                break
     i<n-1 and s[i:i+2]=="BC" i<n-1 i n-1 n 1 s[i:i+2]=="BC" s[i:i+2] s i:i+2 i i+2 i 2 "BC" ans+=a ans a i+=2 i 2 while i<n:
            if s[i]=="A":
                a+=1
                i+=1
            elif i<n-1 and s[i:i+2]=="BC":
                ans+=a
                i+=2
            else:
                a=0
                i+=1
                break
     i<n i n if s[i]=="A":
                a+=1
                i+=1
            elif i<n-1 and s[i:i+2]=="BC":
                ans+=a
                i+=2
            else:
                a=0
                i+=1
                break
     s[i]=="A" s[i] s i "A" a+=1 a 1 i+=1 i 1 elif i<n-1 and s[i:i+2]=="BC":
                ans+=a
                i+=2
             i<n-1 and s[i:i+2]=="BC" i<n-1 i n-1 n 1 s[i:i+2]=="BC" s[i:i+2] s i:i+2 i i+2 i 2 "BC" ans+=a ans a i+=2 i 2 a=0 a 0 i+=1 i 1 break i+=1 i 1 a=0 a 0 print(ans) print ans n=len(s) len(s) n i+=1 1 i a+=1 1 a a+=1 1 a a,ans=0,0,0 0 a i+=1 1 i i+=2 2 i ans=0,0,0 0 ans i+=1 1 i i+=2 2 i i+=1 1 i a=0 0 a s=input() input() s i,a,ans=0,0,0 0 i a=0 0 a ans+=a a ans ans+=a a ans
s=input()
n=len(s)
i,a,ans=0,0,0
while i<n:
    if s[i]=="A":
        a+=1
        i+=1
    elif i<n-1 and s[i:i+2]=="BC":
        ans+=a
        i+=2
        while i<n:
            if s[i]=="A":
                a+=1
                i+=1
            elif i<n-1 and s[i:i+2]=="BC":
                ans+=a
                i+=2
            else:
                a=0
                i+=1
                break
    else:
        i+=1
        a=0
print(ans)