s=input()
t=''
i=0
while(i<len(s)):
    if i<len(s)-1 and s[i:i+2]=='BC':
        t+='D'
        i+=2
    else:
        t+=s[i]
        i+=1
t=t[::-1]
N=len(t)
i=0
ans=0
while(i<N):
    if t[i]=='D':
        j=i
        cnt=0
        while(j<N and t[j]!='B' and t[j]!='C'):
            if t[j]=='D':
                cnt+=1
            else:
                ans+=cnt
            j+=1
        i=j
    i+=1
print(ans) s=input() s input() input t='' t '' i=0 i 0 while(i<len(s)):
    if i<len(s)-1 and s[i:i+2]=='BC':
        t+='D'
        i+=2
    else:
        t+=s[i]
        i+=1 i<len(s) i len(s) len s if i<len(s)-1 and s[i:i+2]=='BC':
        t+='D'
        i+=2
    else:
        t+=s[i]
        i+=1 i<len(s)-1 and s[i:i+2]=='BC' i<len(s)-1 i len(s)-1 len(s) len s 1 s[i:i+2]=='BC' s[i:i+2] s i:i+2 i i+2 i 2 'BC' t+='D' t 'D' i+=2 i 2 t+=s[i] t s[i] s i i+=1 i 1 t=t[::-1] t t[::-1] t ::-1 -1 N=len(t) N len(t) len t i=0 i 0 ans=0 ans 0 while(i<N):
    if t[i]=='D':
        j=i
        cnt=0
        while(j<N and t[j]!='B' and t[j]!='C'):
            if t[j]=='D':
                cnt+=1
            else:
                ans+=cnt
            j+=1
        i=j
    i+=1 i<N i N if t[i]=='D':
        j=i
        cnt=0
        while(j<N and t[j]!='B' and t[j]!='C'):
            if t[j]=='D':
                cnt+=1
            else:
                ans+=cnt
            j+=1
        i=j
     t[i]=='D' t[i] t i 'D' j=i j i cnt=0 cnt 0 while(j<N and t[j]!='B' and t[j]!='C'):
            if t[j]=='D':
                cnt+=1
            else:
                ans+=cnt
            j+=1
         j<N and t[j]!='B' and t[j]!='C' j<N and t[j]!='B' j<N j N t[j]!='B' t[j] t j 'B' t[j]!='C' t[j] t j 'C' if t[j]=='D':
                cnt+=1
            else:
                ans+=cnt
             t[j]=='D' t[j] t j 'D' cnt+=1 cnt 1 ans+=cnt ans cnt j+=1 j 1 i=j i j i+=1 i 1 print(ans) print ans i=j j i t=t[::-1] t[::-1] t i+=1 1 i i=0 0 i ans+=cnt cnt ans i+=1 1 i t+=s[i] s[i] t cnt+=1 1 cnt N=len(t) len(t) N ans=0 0 ans i=0 0 i j+=1 1 j i+=2 2 i cnt=0 0 cnt t='' '' t j=i i j s=input() input() s t+='D' 'D' t
s=input()
t=''
i=0
while(i<len(s)):
    if i<len(s)-1 and s[i:i+2]=='BC':
        t+='D'
        i+=2
    else:
        t+=s[i]
        i+=1
t=t[::-1]
N=len(t)
i=0
ans=0
while(i<N):
    if t[i]=='D':
        j=i
        cnt=0
        while(j<N and t[j]!='B' and t[j]!='C'):
            if t[j]=='D':
                cnt+=1
            else:
                ans+=cnt
            j+=1
        i=j
    i+=1
print(ans)