s = input()
a_cnt=0
ans=0
i=0
while i < len(s)-1:
    if s[i] == "A":
        a_cnt+=1
        i+=1
    elif s[i] == "B" and s[i+1] == "C":
        ans+=a_cnt
        i+=2
    else:
        a_cnt=0
        i+=1
print(ans) s = input() s input() input a_cnt=0 a_cnt 0 ans=0 ans 0 i=0 i 0 while i < len(s)-1:
    if s[i] == "A":
        a_cnt+=1
        i+=1
    elif s[i] == "B" and s[i+1] == "C":
        ans+=a_cnt
        i+=2
    else:
        a_cnt=0
        i+=1 i < len(s)-1 i len(s)-1 len(s) len s 1 if s[i] == "A":
        a_cnt+=1
        i+=1
    elif s[i] == "B" and s[i+1] == "C":
        ans+=a_cnt
        i+=2
    else:
        a_cnt=0
        i+=1 s[i] == "A" s[i] s i "A" a_cnt+=1 a_cnt 1 i+=1 i 1 elif s[i] == "B" and s[i+1] == "C":
        ans+=a_cnt
        i+=2
     s[i] == "B" and s[i+1] == "C" s[i] == "B" s[i] s i "B" s[i+1] == "C" s[i+1] s i+1 i 1 "C" ans+=a_cnt ans a_cnt i+=2 i 2 a_cnt=0 a_cnt 0 i+=1 i 1 print(ans) print ans i+=2 2 i i+=1 1 i i+=1 1 i ans+=a_cnt a_cnt ans a_cnt=0 0 a_cnt i=0 0 i s = input() input() s ans=0 0 ans a_cnt+=1 1 a_cnt a_cnt=0 0 a_cnt
s = input()
a_cnt=0
ans=0
i=0
while i < len(s)-1:
    if s[i] == "A":
        a_cnt+=1
        i+=1
    elif s[i] == "B" and s[i+1] == "C":
        ans+=a_cnt
        i+=2
    else:
        a_cnt=0
        i+=1
print(ans)