s = list(input()) #sys.stdin.readlineは最後が改行

def mergecount(A):
    cnt = 0
    n = len(A)
    if n>1:
        A1 = A[:n>>1]
        A2 = A[n>>1:]
        cnt += mergecount(A1)
        cnt += mergecount(A2)
        i1=0
        i2=0
        for i in range(n):
            if i2 == len(A2):
                A[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
            else:
                A[i] = A2[i2]
                i2 += 1
                cnt += n//2 - i1
    return cnt

ans=0
ss = []
i=0
finish_calc = 0
while i<len(s):
    if s[i]=='A':
        ss.append(1)
        i+=1
        finish_calc=0
    elif i+1<len(s):
        if s[i]=='B' and s[i+1]=='C':
            ss.append(0)
            finish_calc=0
            i+=2
            continue
        if finish_calc==0:
            ans += mergecount(ss)
            ss=[]
            i+=1
            finish_calc=1
        else:
            i+=1
    elif finish_calc==0:
        ans += mergecount(ss)
        ss=[]
        i+=1
        finish_calc=1
    else:
        i+=1

if finish_calc==0:
    ans += mergecount(ss)

print(ans)
 s = list(input()) s list(input()) list input() input def mergecount(A):
    cnt = 0
    n = len(A)
    if n>1:
        A1 = A[:n>>1]
        A2 = A[n>>1:]
        cnt += mergecount(A1)
        cnt += mergecount(A2)
        i1=0
        i2=0
        for i in range(n):
            if i2 == len(A2):
                A[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
            else:
                A[i] = A2[i2]
                i2 += 1
                cnt += n//2 - i1
    return cnt mergecount cnt = 0 cnt 0 n = len(A) n len(A) len A if n>1:
        A1 = A[:n>>1]
        A2 = A[n>>1:]
        cnt += mergecount(A1)
        cnt += mergecount(A2)
        i1=0
        i2=0
        for i in range(n):
            if i2 == len(A2):
                A[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
            else:
                A[i] = A2[i2]
                i2 += 1
                cnt += n//2 - i1
     n>1 n 1 A1 = A[:n>>1] A1 A[:n>>1] A :n>>1 n>>1 n 1 A2 = A[n>>1:] A2 A[n>>1:] A n>>1: n>>1 n 1 cnt += mergecount(A1) cnt mergecount(A1) mergecount A1 cnt += mergecount(A2) cnt mergecount(A2) mergecount A2 i1=0 i1 0 i2=0 i2 0 for i in range(n):
            if i2 == len(A2):
                A[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
            else:
                A[i] = A2[i2]
                i2 += 1
                cnt += n//2 - i1
     i range(n) range n if i2 == len(A2):
                A[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
            else:
                A[i] = A2[i2]
                i2 += 1
                cnt += n//2 - i1
     i2 == len(A2) i2 len(A2) len A2 A[i] = A1[i1] A[i] A i A1[i1] A1 i1 i1 += 1 i1 1 elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
             i1 == len(A1) i1 len(A1) len A1 A[i] = A2[i2] A[i] A i A2[i2] A2 i2 i2 += 1 i2 1 elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
             A1[i1] <= A2[i2] A1[i1] A1 i1 A2[i2] A2 i2 A[i] = A1[i1] A[i] A i A1[i1] A1 i1 i1 += 1 i1 1 A[i] = A2[i2] A[i] A i A2[i2] A2 i2 i2 += 1 i2 1 cnt += n//2 - i1 cnt n//2 - i1 n//2 n 2 i1 return cnt cnt A A ans=0 ans 0 ss = [] ss [] i=0 i 0 finish_calc = 0 finish_calc 0 while i<len(s):
    if s[i]=='A':
        ss.append(1)
        i+=1
        finish_calc=0
    elif i+1<len(s):
        if s[i]=='B' and s[i+1]=='C':
            ss.append(0)
            finish_calc=0
            i+=2
            continue
        if finish_calc==0:
            ans += mergecount(ss)
            ss=[]
            i+=1
            finish_calc=1
        else:
            i+=1
    elif finish_calc==0:
        ans += mergecount(ss)
        ss=[]
        i+=1
        finish_calc=1
    else:
        i+=1 i<len(s) i len(s) len s if s[i]=='A':
        ss.append(1)
        i+=1
        finish_calc=0
    elif i+1<len(s):
        if s[i]=='B' and s[i+1]=='C':
            ss.append(0)
            finish_calc=0
            i+=2
            continue
        if finish_calc==0:
            ans += mergecount(ss)
            ss=[]
            i+=1
            finish_calc=1
        else:
            i+=1
    elif finish_calc==0:
        ans += mergecount(ss)
        ss=[]
        i+=1
        finish_calc=1
    else:
        i+=1 s[i]=='A' s[i] s i 'A' ss.append(1) ss.append ss append 1 i+=1 i 1 finish_calc=0 finish_calc 0 elif i+1<len(s):
        if s[i]=='B' and s[i+1]=='C':
            ss.append(0)
            finish_calc=0
            i+=2
            continue
        if finish_calc==0:
            ans += mergecount(ss)
            ss=[]
            i+=1
            finish_calc=1
        else:
            i+=1
     i+1<len(s) i+1 i 1 len(s) len s if s[i]=='B' and s[i+1]=='C':
            ss.append(0)
            finish_calc=0
            i+=2
            continue
         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' ss.append(0) ss.append ss append 0 finish_calc=0 finish_calc 0 i+=2 i 2 continue if finish_calc==0:
            ans += mergecount(ss)
            ss=[]
            i+=1
            finish_calc=1
        else:
            i+=1
     finish_calc==0 finish_calc 0 ans += mergecount(ss) ans mergecount(ss) mergecount ss ss=[] ss [] i+=1 i 1 finish_calc=1 finish_calc 1 i+=1 i 1 elif finish_calc==0:
        ans += mergecount(ss)
        ss=[]
        i+=1
        finish_calc=1
     finish_calc==0 finish_calc 0 ans += mergecount(ss) ans mergecount(ss) mergecount ss ss=[] ss [] i+=1 i 1 finish_calc=1 finish_calc 1 i+=1 i 1 if finish_calc==0:
    ans += mergecount(ss) finish_calc==0 finish_calc 0 ans += mergecount(ss) ans mergecount(ss) mergecount ss print(ans) print ans i+=1 1 i def mergecount(A):
    cnt = 0
    n = len(A)
    if n>1:
        A1 = A[:n>>1]
        A2 = A[n>>1:]
        cnt += mergecount(A1)
        cnt += mergecount(A2)
        i1=0
        i2=0
        for i in range(n):
            if i2 == len(A2):
                A[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
            else:
                A[i] = A2[i2]
                i2 += 1
                cnt += n//2 - i1
    return cnt def mergecount(A):
    cnt = 0
    n = len(A)
    if n>1:
        A1 = A[:n>>1]
        A2 = A[n>>1:]
        cnt += mergecount(A1)
        cnt += mergecount(A2)
        i1=0
        i2=0
        for i in range(n):
            if i2 == len(A2):
                A[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
            else:
                A[i] = A2[i2]
                i2 += 1
                cnt += n//2 - i1
    return cnt mergecount ans += mergecount(ss) mergecount(ss) ans ss=[] [] ss ans=0 0 ans i+=1 1 i finish_calc=1 1 finish_calc i+=1 1 i i+=1 1 i ss=[] [] ss finish_calc=0 0 finish_calc s = list(input()) list(input()) s finish_calc=0 0 finish_calc finish_calc=1 1 finish_calc i=0 0 i i+=1 1 i finish_calc = 0 0 finish_calc ans += mergecount(ss) mergecount(ss) ans i+=2 2 i ss = [] [] ss ans += mergecount(ss) mergecount(ss) ans
s = list(input()) #sys.stdin.readlineは最後が改行

def mergecount(A):
    cnt = 0
    n = len(A)
    if n>1:
        A1 = A[:n>>1]
        A2 = A[n>>1:]
        cnt += mergecount(A1)
        cnt += mergecount(A2)
        i1=0
        i2=0
        for i in range(n):
            if i2 == len(A2):
                A[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
            else:
                A[i] = A2[i2]
                i2 += 1
                cnt += n//2 - i1
    return cnt

ans=0
ss = []
i=0
finish_calc = 0
while i<len(s):
    if s[i]=='A':
        ss.append(1)
        i+=1
        finish_calc=0
    elif i+1<len(s):
        if s[i]=='B' and s[i+1]=='C':
            ss.append(0)
            finish_calc=0
            i+=2
            continue
        if finish_calc==0:
            ans += mergecount(ss)
            ss=[]
            i+=1
            finish_calc=1
        else:
            i+=1
    elif finish_calc==0:
        ans += mergecount(ss)
        ss=[]
        i+=1
        finish_calc=1
    else:
        i+=1

if finish_calc==0:
    ans += mergecount(ss)

print(ans)

