s=input()
N=len(s)
ans=0
data=[]
i=0
while N>i:
    if s[i]=='A':
        data.append('X')
        i+=1
    elif s[i]=='B' and i<len(s)-1 and s[i+1]=='C':
        data.append('A')
        i+=2
    else:
        index=[]
        count=0
        for j in range(0,len(data)):
            if data[j]=='A':
                index.append(j)
                count+=1

        for j in range(count):
            ans+=index[j]-j
        data=[]
        i+=1
else:
    if data:
        index=[]
        count=0
        for j in range(0,len(data)):
            if data[j]=='A':
                index.append(j)
                count+=1

        s=0
        for j in range(count):
            s+=index[j]-j

        ans+=s

print(ans) s=input() s input() input N=len(s) N len(s) len s ans=0 ans 0 data=[] data [] i=0 i 0 while N>i:
    if s[i]=='A':
        data.append('X')
        i+=1
    elif s[i]=='B' and i<len(s)-1 and s[i+1]=='C':
        data.append('A')
        i+=2
    else:
        index=[]
        count=0
        for j in range(0,len(data)):
            if data[j]=='A':
                index.append(j)
                count+=1

        for j in range(count):
            ans+=index[j]-j
        data=[]
        i+=1
else:
    if data:
        index=[]
        count=0
        for j in range(0,len(data)):
            if data[j]=='A':
                index.append(j)
                count+=1

        s=0
        for j in range(count):
            s+=index[j]-j

        ans+=s N>i N i if s[i]=='A':
        data.append('X')
        i+=1
    elif s[i]=='B' and i<len(s)-1 and s[i+1]=='C':
        data.append('A')
        i+=2
    else:
        index=[]
        count=0
        for j in range(0,len(data)):
            if data[j]=='A':
                index.append(j)
                count+=1

        for j in range(count):
            ans+=index[j]-j
        data=[]
        i+=1 s[i]=='A' s[i] s i 'A' data.append('X') data.append data append 'X' i+=1 i 1 elif s[i]=='B' and i<len(s)-1 and s[i+1]=='C':
        data.append('A')
        i+=2
     s[i]=='B' and i<len(s)-1 and s[i+1]=='C' s[i]=='B' and i<len(s)-1 s[i]=='B' s[i] s i 'B' i<len(s)-1 i len(s)-1 len(s) len s 1 s[i+1]=='C' s[i+1] s i+1 i 1 'C' data.append('A') data.append data append 'A' i+=2 i 2 index=[] index [] count=0 count 0 for j in range(0,len(data)):
            if data[j]=='A':
                index.append(j)
                count+=1

         j range(0,len(data)) range 0 len(data) len data if data[j]=='A':
                index.append(j)
                count+=1

         data[j]=='A' data[j] data j 'A' index.append(j) index.append index append j count+=1 count 1 for j in range(count):
            ans+=index[j]-j
         j range(count) range count ans+=index[j]-j ans index[j]-j index[j] index j j data=[] data [] i+=1 i 1 if data:
        index=[]
        count=0
        for j in range(0,len(data)):
            if data[j]=='A':
                index.append(j)
                count+=1

        s=0
        for j in range(count):
            s+=index[j]-j

        ans+=s data index=[] index [] count=0 count 0 for j in range(0,len(data)):
            if data[j]=='A':
                index.append(j)
                count+=1

         j range(0,len(data)) range 0 len(data) len data if data[j]=='A':
                index.append(j)
                count+=1

         data[j]=='A' data[j] data j 'A' index.append(j) index.append index append j count+=1 count 1 s=0 s 0 for j in range(count):
            s+=index[j]-j

         j range(count) range count s+=index[j]-j s index[j]-j index[j] index j j ans+=s ans s print(ans) print ans ans+=s s ans s=0 0 s index=[] [] index index=[] [] index N=len(s) len(s) N ans=0 0 ans count=0 0 count count+=1 1 count i+=1 1 i i=0 0 i count=0 0 count ans+=index[j]-j index[j]-j ans data=[] [] data i+=2 2 i count+=1 1 count s=input() input() s data=[] [] data i+=1 1 i s+=index[j]-j index[j]-j s
s=input()
N=len(s)
ans=0
data=[]
i=0
while N>i:
    if s[i]=='A':
        data.append('X')
        i+=1
    elif s[i]=='B' and i<len(s)-1 and s[i+1]=='C':
        data.append('A')
        i+=2
    else:
        index=[]
        count=0
        for j in range(0,len(data)):
            if data[j]=='A':
                index.append(j)
                count+=1

        for j in range(count):
            ans+=index[j]-j
        data=[]
        i+=1
else:
    if data:
        index=[]
        count=0
        for j in range(0,len(data)):
            if data[j]=='A':
                index.append(j)
                count+=1

        s=0
        for j in range(count):
            s+=index[j]-j

        ans+=s

print(ans)