import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


s = input()
#a = list(map(int, input().split()))

mode=0
ans=0
anum=0
banum=0
for i in range(len(s)):
    if(mode==0 and s[i]=='A'):
        anum+=1
    elif(mode==1 and s[i]=='A'):
        anum=1
        mode=0
    elif(mode==0 and s[i]=='B'):
        mode=1
    elif(mode==1 and s[i]=='B'):
        mode=0
        anum=0
    elif(mode==0 and s[i]=='C'):
        mode=0
        anum=0
    elif(mode==1 and s[i]=='C'):
        mode=0
        ans += anum
    #print(ans)

print(ans) import math math def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors make_divisors divisors = [] divisors [] for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
     i range(1, int(n**0.5)+1) range 1 int(n**0.5)+1 int(n**0.5) int n**0.5 n 0.5 1 if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
     n % i == 0 n % i n i 0 divisors.append(i) divisors.append divisors append i if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
     i != n // i i n // i n i divisors.append(n//i) divisors.append divisors append n//i n i return divisors divisors n n s = input() s input() input mode=0 mode 0 ans=0 ans 0 anum=0 anum 0 banum=0 banum 0 for i in range(len(s)):
    if(mode==0 and s[i]=='A'):
        anum+=1
    elif(mode==1 and s[i]=='A'):
        anum=1
        mode=0
    elif(mode==0 and s[i]=='B'):
        mode=1
    elif(mode==1 and s[i]=='B'):
        mode=0
        anum=0
    elif(mode==0 and s[i]=='C'):
        mode=0
        anum=0
    elif(mode==1 and s[i]=='C'):
        mode=0
        ans += anum
    #print(ans) i range(len(s)) range len(s) len s if(mode==0 and s[i]=='A'):
        anum+=1
    elif(mode==1 and s[i]=='A'):
        anum=1
        mode=0
    elif(mode==0 and s[i]=='B'):
        mode=1
    elif(mode==1 and s[i]=='B'):
        mode=0
        anum=0
    elif(mode==0 and s[i]=='C'):
        mode=0
        anum=0
    elif(mode==1 and s[i]=='C'):
        mode=0
        ans += anum
    #print(ans) mode==0 and s[i]=='A' mode==0 mode 0 s[i]=='A' s[i] s i 'A' anum+=1 anum 1 elif(mode==1 and s[i]=='A'):
        anum=1
        mode=0
     mode==1 and s[i]=='A' mode==1 mode 1 s[i]=='A' s[i] s i 'A' anum=1 anum 1 mode=0 mode 0 elif(mode==0 and s[i]=='B'):
        mode=1
     mode==0 and s[i]=='B' mode==0 mode 0 s[i]=='B' s[i] s i 'B' mode=1 mode 1 elif(mode==1 and s[i]=='B'):
        mode=0
        anum=0
     mode==1 and s[i]=='B' mode==1 mode 1 s[i]=='B' s[i] s i 'B' mode=0 mode 0 anum=0 anum 0 elif(mode==0 and s[i]=='C'):
        mode=0
        anum=0
     mode==0 and s[i]=='C' mode==0 mode 0 s[i]=='C' s[i] s i 'C' mode=0 mode 0 anum=0 anum 0 elif(mode==1 and s[i]=='C'):
        mode=0
        ans += anum
    #print(ans) mode==1 and s[i]=='C' mode==1 mode 1 s[i]=='C' s[i] s i 'C' mode=0 mode 0 ans += anum ans anum print(ans) print ans mode=0 0 mode ans=0 0 ans anum=0 0 anum mode=0 0 mode anum=1 1 anum anum+=1 1 anum anum=0 0 anum anum=0 0 anum ans += anum anum ans s = input() input() s def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors make_divisors banum=0 0 banum mode=0 0 mode mode=0 0 mode mode=0 0 mode mode=1 1 mode
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


s = input()
#a = list(map(int, input().split()))

mode=0
ans=0
anum=0
banum=0
for i in range(len(s)):
    if(mode==0 and s[i]=='A'):
        anum+=1
    elif(mode==1 and s[i]=='A'):
        anum=1
        mode=0
    elif(mode==0 and s[i]=='B'):
        mode=1
    elif(mode==1 and s[i]=='B'):
        mode=0
        anum=0
    elif(mode==0 and s[i]=='C'):
        mode=0
        anum=0
    elif(mode==1 and s[i]=='C'):
        mode=0
        ans += anum
    #print(ans)

print(ans)
