s = input() + '?'

ans = 0
n_a = 0
n_bc = 0
i = 0
while(i<len(s)):
    if(s[i:i+2]=='BC'):
        n_bc += 1
        i += 2
        continue
    else:
        ans += n_a * n_bc
        n_bc = 0
        if(s[i]=='A'):
            n_a += 1
        else:
            n_a = 0
        i += 1

print(ans) s = input() + '?' s input() + '?' input() input '?' ans = 0 ans 0 n_a = 0 n_a 0 n_bc = 0 n_bc 0 i = 0 i 0 while(i<len(s)):
    if(s[i:i+2]=='BC'):
        n_bc += 1
        i += 2
        continue
    else:
        ans += n_a * n_bc
        n_bc = 0
        if(s[i]=='A'):
            n_a += 1
        else:
            n_a = 0
        i += 1 i<len(s) i len(s) len s if(s[i:i+2]=='BC'):
        n_bc += 1
        i += 2
        continue
    else:
        ans += n_a * n_bc
        n_bc = 0
        if(s[i]=='A'):
            n_a += 1
        else:
            n_a = 0
        i += 1 s[i:i+2]=='BC' s[i:i+2] s i:i+2 i i+2 i 2 'BC' n_bc += 1 n_bc 1 i += 2 i 2 continue ans += n_a * n_bc ans n_a * n_bc n_a n_bc n_bc = 0 n_bc 0 if(s[i]=='A'):
            n_a += 1
        else:
            n_a = 0
         s[i]=='A' s[i] s i 'A' n_a += 1 n_a 1 n_a = 0 n_a 0 i += 1 i 1 print(ans) print ans n_bc += 1 1 n_bc ans += n_a * n_bc n_a * n_bc ans i += 2 2 i i += 1 1 i i = 0 0 i n_a = 0 0 n_a n_bc = 0 0 n_bc s = input() + '?' input() + '?' s n_bc = 0 0 n_bc n_a += 1 1 n_a n_a = 0 0 n_a ans = 0 0 ans
s = input() + '?'

ans = 0
n_a = 0
n_bc = 0
i = 0
while(i<len(s)):
    if(s[i:i+2]=='BC'):
        n_bc += 1
        i += 2
        continue
    else:
        ans += n_a * n_bc
        n_bc = 0
        if(s[i]=='A'):
            n_a += 1
        else:
            n_a = 0
        i += 1

print(ans)