# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for s in S.split():
        a = 0
        for c in s:
            if c == 'A':
                a += 1
            else:
                ans += a
    return ans

def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main() import bisect bisect import heapq heapq import math math import random random import sys sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) sys.setrecursionlimit sys setrecursionlimit 100000 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline INF = 2**62-1 INF 2**62-1 2**62 2 62 1 def read_int():
    return int(input()) read_int return int(input()) int(input()) int input() input def read_int_n():
    return list(map(int, input().split())) read_int_n return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def read_float():
    return float(input()) read_float return float(input()) float(input()) float input() input def read_float_n():
    return list(map(float, input().split())) read_float_n return list(map(float, input().split())) list(map(float, input().split())) list map(float, input().split()) map float input().split() ().split () input split def read_str():
    return input().strip() read_str return input().strip() input().strip() ().strip () input strip def read_str_n():
    return list(map(str, input().split())) read_str_n return list(map(str, input().split())) list(map(str, input().split())) list map(str, input().split()) map str input().split() ().split () input split def error_print(*args):
    print(*args, file=sys.stderr) error_print print(*args, file=sys.stderr) print *args args file=sys.stderr file sys.stderr sys stderr *args def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap mt import time time def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

     wrap s = time.time() s time.time() time.time time time ret = f(*args, **kwargs) ret f(*args, **kwargs) f *args args **kwargs kwargs e = time.time() e time.time() time.time time time error_print(e - s, 'sec') error_print e - s e s 'sec' return ret ret *args **kwargs return wrap wrap f f def slv(S):
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for s in S.split():
        a = 0
        for c in s:
            if c == 'A':
                a += 1
            else:
                ans += a
    return ans slv S = S.replace('BC', 'D') S S.replace('BC', 'D') S.replace S replace 'BC' 'D' S = S.replace('B', ' ') S S.replace('B', ' ') S.replace S replace 'B' ' ' S = S.replace('C', ' ') S S.replace('C', ' ') S.replace S replace 'C' ' ' ans = 0 ans 0 for s in S.split():
        a = 0
        for c in s:
            if c == 'A':
                a += 1
            else:
                ans += a
     s S.split() S.split S split a = 0 a 0 for c in s:
            if c == 'A':
                a += 1
            else:
                ans += a
     c s if c == 'A':
                a += 1
            else:
                ans += a
     c == 'A' c 'A' a += 1 a 1 ans += a ans a return ans ans S S @mt slv mt slv def main():
    S = read_str()
    print(slv(S)) main S = read_str() S read_str() read_str print(slv(S)) print slv(S) slv S if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def read_float_n():
    return list(map(float, input().split())) def read_float_n():
    return list(map(float, input().split())) read_float_n def slv(S):
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for s in S.split():
        a = 0
        for c in s:
            if c == 'A':
                a += 1
            else:
                ans += a
    return ans def slv(S):
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for s in S.split():
        a = 0
        for c in s:
            if c == 'A':
                a += 1
            else:
                ans += a
    return ans slv def read_str_n():
    return list(map(str, input().split())) def read_str_n():
    return list(map(str, input().split())) read_str_n def read_float():
    return float(input()) def read_float():
    return float(input()) read_float INF = 2**62-1 2**62-1 INF def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap mt input = sys.stdin.readline sys.stdin.readline input def error_print(*args):
    print(*args, file=sys.stderr) def error_print(*args):
    print(*args, file=sys.stderr) error_print def read_int_n():
    return list(map(int, input().split())) def read_int_n():
    return list(map(int, input().split())) read_int_n def read_str():
    return input().strip() def read_str():
    return input().strip() read_str def read_int():
    return int(input()) def read_int():
    return int(input()) read_int def main():
    S = read_str()
    print(slv(S)) def main():
    S = read_str()
    print(slv(S)) main
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for s in S.split():
        a = 0
        for c in s:
            if c == 'A':
                a += 1
            else:
                ans += a
    return ans

def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()
