import sys, math, re
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

s = input()
s = s.replace('BC', 'D')
matches = re.findall(r'[AD]+', s)
ans = 0
for w in matches:
    n = len(w)
    p = n-1
    for i in range(n-1, -1, -1):
        if w[i] == 'A':
            ans += p-i
            p -= 1

print(ans) import sys, math, re sys math re from functools import lru_cache from collections import deque sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 MOD = 10**9+7 MOD 10**9+7 10**9 10 9 7 def input():
    return sys.stdin.readline()[:-1] input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 def mi():
    return map(int, input().split()) mi return map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split def ii():
    return int(input()) ii return int(input()) int(input()) int input() input def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)] i2 list(mi()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) list(mi()) list mi() mi tmp = [list(mi()) for i in range(n)] tmp [list(mi()) for i in range(n)] list(i) for i in zip(*tmp) for i in zip(*tmp) i zip(*tmp) zip *tmp tmp for i in zip(*tmp) list(i) list i return [list(i) for i in zip(*tmp)] [list(i) for i in zip(*tmp)] n n s = input() s input() input s = s.replace('BC', 'D') s s.replace('BC', 'D') s.replace s replace 'BC' 'D' matches = re.findall(r'[AD]+', s) matches re.findall(r'[AD]+', s) re.findall re findall r'[AD]+' s ans = 0 ans 0 for w in matches:
    n = len(w)
    p = n-1
    for i in range(n-1, -1, -1):
        if w[i] == 'A':
            ans += p-i
            p -= 1 w matches n = len(w) n len(w) len w p = n-1 p n-1 n 1 for i in range(n-1, -1, -1):
        if w[i] == 'A':
            ans += p-i
            p -= 1 i range(n-1, -1, -1) range n-1 n 1 -1 -1 if w[i] == 'A':
            ans += p-i
            p -= 1 w[i] == 'A' w[i] w i 'A' ans += p-i ans p-i p i p -= 1 p 1 print(ans) print ans def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)] def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)] i2 def mi():
    return map(int, input().split()) def mi():
    return map(int, input().split()) mi MOD = 10**9+7 10**9+7 MOD ans += p-i p-i ans s = input() input() s s = s.replace('BC', 'D') s.replace('BC', 'D') s def input():
    return sys.stdin.readline()[:-1] def input():
    return sys.stdin.readline()[:-1] input def ii():
    return int(input()) def ii():
    return int(input()) ii p -= 1 1 p n = len(w) len(w) n matches = re.findall(r'[AD]+', s) re.findall(r'[AD]+', s) matches p = n-1 n-1 p ans = 0 0 ans
import sys, math, re
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

s = input()
s = s.replace('BC', 'D')
matches = re.findall(r'[AD]+', s)
ans = 0
for w in matches:
    n = len(w)
    p = n-1
    for i in range(n-1, -1, -1):
        if w[i] == 'A':
            ans += p-i
            p -= 1

print(ans)