S=input()

i=0
T=[]
while i<len(S):

    if i+1<len(S) and S[i]+S[i+1]=="BC":
        T.append("D")
        i+=2
    else:
        T.append(S[i])
        i+=1
count=0
m=0
Acount=0
#print(T)
for i in range(len(T)):
    if "A"==T[i]:
        Acount+=1
    elif "D"==T[i]:
        count+=Acount
    else:
        Acount=0



#print(T)
print(count) S=input() S input() input i=0 i 0 T=[] T [] while i<len(S):

    if i+1<len(S) and S[i]+S[i+1]=="BC":
        T.append("D")
        i+=2
    else:
        T.append(S[i])
        i+=1 i<len(S) i len(S) len S if i+1<len(S) and S[i]+S[i+1]=="BC":
        T.append("D")
        i+=2
    else:
        T.append(S[i])
        i+=1 i+1<len(S) and S[i]+S[i+1]=="BC" i+1<len(S) i+1 i 1 len(S) len S S[i]+S[i+1]=="BC" S[i]+S[i+1] S[i] S i S[i+1] S i+1 i 1 "BC" T.append("D") T.append T append "D" i+=2 i 2 T.append(S[i]) T.append T append S[i] S i i+=1 i 1 count=0 count 0 m=0 m 0 Acount=0 Acount 0 for i in range(len(T)):
    if "A"==T[i]:
        Acount+=1
    elif "D"==T[i]:
        count+=Acount
    else:
        Acount=0



#print(T) i range(len(T)) range len(T) len T if "A"==T[i]:
        Acount+=1
    elif "D"==T[i]:
        count+=Acount
    else:
        Acount=0



#print(T) "A"==T[i] "A" T[i] T i Acount+=1 Acount 1 elif "D"==T[i]:
        count+=Acount
     "D"==T[i] "D" T[i] T i count+=Acount count Acount Acount=0 Acount 0 print(count) print count i+=2 2 i i+=1 1 i S=input() input() S count+=Acount Acount count T=[] [] T Acount+=1 1 Acount m=0 0 m Acount=0 0 Acount count=0 0 count i=0 0 i Acount=0 0 Acount
S=input()

i=0
T=[]
while i<len(S):

    if i+1<len(S) and S[i]+S[i+1]=="BC":
        T.append("D")
        i+=2
    else:
        T.append(S[i])
        i+=1
count=0
m=0
Acount=0
#print(T)
for i in range(len(T)):
    if "A"==T[i]:
        Acount+=1
    elif "D"==T[i]:
        count+=Acount
    else:
        Acount=0



#print(T)
print(count)
