S=input()
#ABCBCBC
N=len(S)
if N<3:
    print(0)
    exit()
S=list(S)
#abc前にaが続く数
As=0
#abcごにbc続く数
BCs=0
ans=0
flag=False
safe=-1
for i in range(N-2):
    if "".join(S[i:i+3])=="ABC":
        ans+=1
        ans+=As


        S[i]="B"
        S[i+1]="C"
        S[i+2]="A"
        safe=i+1

    elif S[i]=="A":
        As+=1
    else:
        if i!=safe:
            As=0
    #print(As)

print(ans) S=input() S input() input N=len(S) N len(S) len S if N<3:
    print(0)
    exit() N<3 N 3 print(0) print 0 exit() exit S=list(S) S list(S) list S As=0 As 0 BCs=0 BCs 0 ans=0 ans 0 flag=False flag False safe=-1 safe -1 for i in range(N-2):
    if "".join(S[i:i+3])=="ABC":
        ans+=1
        ans+=As


        S[i]="B"
        S[i+1]="C"
        S[i+2]="A"
        safe=i+1

    elif S[i]=="A":
        As+=1
    else:
        if i!=safe:
            As=0
    #print(As) i range(N-2) range N-2 N 2 if "".join(S[i:i+3])=="ABC":
        ans+=1
        ans+=As


        S[i]="B"
        S[i+1]="C"
        S[i+2]="A"
        safe=i+1

    elif S[i]=="A":
        As+=1
    else:
        if i!=safe:
            As=0
    #print(As) "".join(S[i:i+3])=="ABC" "".join(S[i:i+3]) "".join "" join S[i:i+3] S i:i+3 i i+3 i 3 "ABC" ans+=1 ans 1 ans+=As ans As S[i]="B" S[i] S i "B" S[i+1]="C" S[i+1] S i+1 i 1 "C" S[i+2]="A" S[i+2] S i+2 i 2 "A" safe=i+1 safe i+1 i 1 elif S[i]=="A":
        As+=1
     S[i]=="A" S[i] S i "A" As+=1 As 1 if i!=safe:
            As=0
    #print(As) i!=safe i safe As=0 As 0 print(ans) print ans S=input() input() S safe=-1 -1 safe As=0 0 As flag=False False flag As+=1 1 As safe=i+1 i+1 safe ans+=1 1 ans ans+=As As ans S=list(S) list(S) S ans=0 0 ans As=0 0 As N=len(S) len(S) N BCs=0 0 BCs
S=input()
#ABCBCBC
N=len(S)
if N<3:
    print(0)
    exit()
S=list(S)
#abc前にaが続く数
As=0
#abcごにbc続く数
BCs=0
ans=0
flag=False
safe=-1
for i in range(N-2):
    if "".join(S[i:i+3])=="ABC":
        ans+=1
        ans+=As


        S[i]="B"
        S[i+1]="C"
        S[i+2]="A"
        safe=i+1

    elif S[i]=="A":
        As+=1
    else:
        if i!=safe:
            As=0
    #print(As)

print(ans)