so=input()

s=""

N=len(so)
i=0
while i<N:
    if so[i]=="A":
        s=s+"A"
        i+=1
    elif so[i:i+2]=="BC":
        s=s+"B"
        i+=2
    elif so[i]=="C" or so[i]=="B":
        s=s+"D"
        i+=1

L=len(s)
f=False
cnt=0
a=0
for i in range(L):
    if s[i]=="A":
        f=True
        a+=1
    elif f and s[i]=="B":
        cnt+=a
    elif s[i]=="D":
        f=False
        a=0
print(cnt) so=input() so input() input s="" s "" N=len(so) N len(so) len so i=0 i 0 while i<N:
    if so[i]=="A":
        s=s+"A"
        i+=1
    elif so[i:i+2]=="BC":
        s=s+"B"
        i+=2
    elif so[i]=="C" or so[i]=="B":
        s=s+"D"
        i+=1 i<N i N if so[i]=="A":
        s=s+"A"
        i+=1
    elif so[i:i+2]=="BC":
        s=s+"B"
        i+=2
    elif so[i]=="C" or so[i]=="B":
        s=s+"D"
        i+=1 so[i]=="A" so[i] so i "A" s=s+"A" s s+"A" s "A" i+=1 i 1 elif so[i:i+2]=="BC":
        s=s+"B"
        i+=2
     so[i:i+2]=="BC" so[i:i+2] so i:i+2 i i+2 i 2 "BC" s=s+"B" s s+"B" s "B" i+=2 i 2 elif so[i]=="C" or so[i]=="B":
        s=s+"D"
        i+=1 so[i]=="C" or so[i]=="B" so[i]=="C" so[i] so i "C" so[i]=="B" so[i] so i "B" s=s+"D" s s+"D" s "D" i+=1 i 1 L=len(s) L len(s) len s f=False f False cnt=0 cnt 0 a=0 a 0 for i in range(L):
    if s[i]=="A":
        f=True
        a+=1
    elif f and s[i]=="B":
        cnt+=a
    elif s[i]=="D":
        f=False
        a=0 i range(L) range L if s[i]=="A":
        f=True
        a+=1
    elif f and s[i]=="B":
        cnt+=a
    elif s[i]=="D":
        f=False
        a=0 s[i]=="A" s[i] s i "A" f=True f True a+=1 a 1 elif f and s[i]=="B":
        cnt+=a
     f and s[i]=="B" f s[i]=="B" s[i] s i "B" cnt+=a cnt a elif s[i]=="D":
        f=False
        a=0 s[i]=="D" s[i] s i "D" f=False f False a=0 a 0 print(cnt) print cnt N=len(so) len(so) N i+=1 1 i f=True True f a=0 0 a s=s+"B" s+"B" s f=False False f cnt+=a a cnt L=len(s) len(s) L s="" "" s s=s+"D" s+"D" s cnt=0 0 cnt so=input() input() so i+=1 1 i s=s+"A" s+"A" s i=0 0 i a=0 0 a f=False False f i+=2 2 i a+=1 1 a
so=input()

s=""

N=len(so)
i=0
while i<N:
    if so[i]=="A":
        s=s+"A"
        i+=1
    elif so[i:i+2]=="BC":
        s=s+"B"
        i+=2
    elif so[i]=="C" or so[i]=="B":
        s=s+"D"
        i+=1

L=len(s)
f=False
cnt=0
a=0
for i in range(L):
    if s[i]=="A":
        f=True
        a+=1
    elif f and s[i]=="B":
        cnt+=a
    elif s[i]=="D":
        f=False
        a=0
print(cnt)
