import sys

def f(s):
    if s=="A":
        return 0
    elif s=="B":
        return 1
    else:
        return 2

S=list(map(f,input()))
N=len(S)

if N<=2:
    print(0)
    sys.exit()

T=0
U=0

I=0
K=0
while I<N-2:
    if (S[I]==0) and (S[I+1]==1) and (S[I+2]==2):
        U+=1
        T+=U
        I+=3
    elif S[I]==0:
        U+=1
        I+=1
    elif (S[I]==1) and (S[I+1]==2):
        T+=U
        I+=2
    else:
        U=0
        I+=1

if (S[-2]==1 and S[-1]==2) and S[-3]!=0:
    T+=U
    
print(T) import sys sys def f(s):
    if s=="A":
        return 0
    elif s=="B":
        return 1
    else:
        return 2 f if s=="A":
        return 0
    elif s=="B":
        return 1
    else:
        return 2 s=="A" s "A" return 0 0 elif s=="B":
        return 1
     s=="B" s "B" return 1 1 return 2 2 s s S=list(map(f,input())) S list(map(f,input())) list map(f,input()) map f input() input N=len(S) N len(S) len S if N<=2:
    print(0)
    sys.exit() N<=2 N 2 print(0) print 0 sys.exit() sys.exit sys exit T=0 T 0 U=0 U 0 I=0 I 0 K=0 K 0 while I<N-2:
    if (S[I]==0) and (S[I+1]==1) and (S[I+2]==2):
        U+=1
        T+=U
        I+=3
    elif S[I]==0:
        U+=1
        I+=1
    elif (S[I]==1) and (S[I+1]==2):
        T+=U
        I+=2
    else:
        U=0
        I+=1 I<N-2 I N-2 N 2 if (S[I]==0) and (S[I+1]==1) and (S[I+2]==2):
        U+=1
        T+=U
        I+=3
    elif S[I]==0:
        U+=1
        I+=1
    elif (S[I]==1) and (S[I+1]==2):
        T+=U
        I+=2
    else:
        U=0
        I+=1 (S[I]==0) and (S[I+1]==1) and (S[I+2]==2) (S[I]==0) and (S[I+1]==1) S[I]==0 S[I] S I 0 S[I+1]==1 S[I+1] S I+1 I 1 1 S[I+2]==2 S[I+2] S I+2 I 2 2 U+=1 U 1 T+=U T U I+=3 I 3 elif S[I]==0:
        U+=1
        I+=1
     S[I]==0 S[I] S I 0 U+=1 U 1 I+=1 I 1 elif (S[I]==1) and (S[I+1]==2):
        T+=U
        I+=2
     (S[I]==1) and (S[I+1]==2) S[I]==1 S[I] S I 1 S[I+1]==2 S[I+1] S I+1 I 1 2 T+=U T U I+=2 I 2 U=0 U 0 I+=1 I 1 if (S[-2]==1 and S[-1]==2) and S[-3]!=0:
    T+=U
     (S[-2]==1 and S[-1]==2) and S[-3]!=0 S[-2]==1 and S[-1]==2 S[-2]==1 S[-2] S -2 1 S[-1]==2 S[-1] S -1 2 S[-3]!=0 S[-3] S -3 0 T+=U T U print(T) print T I=0 0 I I+=1 1 I S=list(map(f,input())) list(map(f,input())) S T+=U U T I+=3 3 I U=0 0 U I+=2 2 I I+=1 1 I T=0 0 T K=0 0 K def f(s):
    if s=="A":
        return 0
    elif s=="B":
        return 1
    else:
        return 2 def f(s):
    if s=="A":
        return 0
    elif s=="B":
        return 1
    else:
        return 2 f U=0 0 U T+=U U T N=len(S) len(S) N T+=U U T U+=1 1 U U+=1 1 U
import sys

def f(s):
    if s=="A":
        return 0
    elif s=="B":
        return 1
    else:
        return 2

S=list(map(f,input()))
N=len(S)

if N<=2:
    print(0)
    sys.exit()

T=0
U=0

I=0
K=0
while I<N-2:
    if (S[I]==0) and (S[I+1]==1) and (S[I+2]==2):
        U+=1
        T+=U
        I+=3
    elif S[I]==0:
        U+=1
        I+=1
    elif (S[I]==1) and (S[I+1]==2):
        T+=U
        I+=2
    else:
        U=0
        I+=1

if (S[-2]==1 and S[-1]==2) and S[-3]!=0:
    T+=U
    
print(T)
