import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(str(input()))
length = len(S)

abc_cnt = 0
a_cnt = 0
ans = 0
for i in range(length):
    s = S[i]
    if s=='A':
        if abc_cnt!=1:
            a_cnt = 0
        a_cnt += 1
        abc_cnt = 1
    elif s=='B':
        if abc_cnt==1:
            abc_cnt += 1
        else:
            a_cnt = 0
            abc_cnt = 0
    else:
        if abc_cnt==2:
            abc_cnt = 1
            ans += a_cnt
        else:
            a_cnt = 0
            abc_cnt = 0
print(ans) import sys sys def input(): return sys.stdin.readline().strip() input def mapint(): return map(int, input().split()) mapint sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 S = list(str(input())) S list(str(input())) list str(input()) str input() input length = len(S) length len(S) len S abc_cnt = 0 abc_cnt 0 a_cnt = 0 a_cnt 0 ans = 0 ans 0 for i in range(length):
    s = S[i]
    if s=='A':
        if abc_cnt!=1:
            a_cnt = 0
        a_cnt += 1
        abc_cnt = 1
    elif s=='B':
        if abc_cnt==1:
            abc_cnt += 1
        else:
            a_cnt = 0
            abc_cnt = 0
    else:
        if abc_cnt==2:
            abc_cnt = 1
            ans += a_cnt
        else:
            a_cnt = 0
            abc_cnt = 0 i range(length) range length s = S[i] s S[i] S i if s=='A':
        if abc_cnt!=1:
            a_cnt = 0
        a_cnt += 1
        abc_cnt = 1
    elif s=='B':
        if abc_cnt==1:
            abc_cnt += 1
        else:
            a_cnt = 0
            abc_cnt = 0
    else:
        if abc_cnt==2:
            abc_cnt = 1
            ans += a_cnt
        else:
            a_cnt = 0
            abc_cnt = 0 s=='A' s 'A' if abc_cnt!=1:
            a_cnt = 0
         abc_cnt!=1 abc_cnt 1 a_cnt = 0 a_cnt 0 a_cnt += 1 a_cnt 1 abc_cnt = 1 abc_cnt 1 elif s=='B':
        if abc_cnt==1:
            abc_cnt += 1
        else:
            a_cnt = 0
            abc_cnt = 0
     s=='B' s 'B' if abc_cnt==1:
            abc_cnt += 1
        else:
            a_cnt = 0
            abc_cnt = 0
     abc_cnt==1 abc_cnt 1 abc_cnt += 1 abc_cnt 1 a_cnt = 0 a_cnt 0 abc_cnt = 0 abc_cnt 0 if abc_cnt==2:
            abc_cnt = 1
            ans += a_cnt
        else:
            a_cnt = 0
            abc_cnt = 0 abc_cnt==2 abc_cnt 2 abc_cnt = 1 abc_cnt 1 ans += a_cnt ans a_cnt a_cnt = 0 a_cnt 0 abc_cnt = 0 abc_cnt 0 print(ans) print ans S = list(str(input())) list(str(input())) S a_cnt += 1 1 a_cnt abc_cnt += 1 1 abc_cnt abc_cnt = 0 0 abc_cnt a_cnt = 0 0 a_cnt def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input def mapint(): return map(int, input().split()) def mapint(): return map(int, input().split()) mapint a_cnt = 0 0 a_cnt ans += a_cnt a_cnt ans a_cnt = 0 0 a_cnt abc_cnt = 1 1 abc_cnt s = S[i] S[i] s abc_cnt = 0 0 abc_cnt length = len(S) len(S) length a_cnt = 0 0 a_cnt ans = 0 0 ans abc_cnt = 0 0 abc_cnt abc_cnt = 1 1 abc_cnt
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(str(input()))
length = len(S)

abc_cnt = 0
a_cnt = 0
ans = 0
for i in range(length):
    s = S[i]
    if s=='A':
        if abc_cnt!=1:
            a_cnt = 0
        a_cnt += 1
        abc_cnt = 1
    elif s=='B':
        if abc_cnt==1:
            abc_cnt += 1
        else:
            a_cnt = 0
            abc_cnt = 0
    else:
        if abc_cnt==2:
            abc_cnt = 1
            ans += a_cnt
        else:
            a_cnt = 0
            abc_cnt = 0
print(ans)