import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    ans = 0
    stack = []
    for c in input():
        if len(stack) >= 2 and stack[-2:] == ["A", "B"] and c == 'C':
            ans += len(stack) - 1
            stack.pop()
        elif len(stack) >= 1 and stack[-1] == 'A' and c in ('A', 'B'):
            stack.append(c)
        elif c == 'A':
            stack = ['A']
        else:
            stack = []
    print(ans)
resolve() import sys sys INF = 1 << 60 INF 1 << 60 1 60 MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 sys.setrecursionlimit(2147483647) sys.setrecursionlimit sys setrecursionlimit 2147483647 input = lambda:sys.stdin.readline().rstrip() input lambda:sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip def resolve():
    ans = 0
    stack = []
    for c in input():
        if len(stack) >= 2 and stack[-2:] == ["A", "B"] and c == 'C':
            ans += len(stack) - 1
            stack.pop()
        elif len(stack) >= 1 and stack[-1] == 'A' and c in ('A', 'B'):
            stack.append(c)
        elif c == 'A':
            stack = ['A']
        else:
            stack = []
    print(ans) resolve ans = 0 ans 0 stack = [] stack [] for c in input():
        if len(stack) >= 2 and stack[-2:] == ["A", "B"] and c == 'C':
            ans += len(stack) - 1
            stack.pop()
        elif len(stack) >= 1 and stack[-1] == 'A' and c in ('A', 'B'):
            stack.append(c)
        elif c == 'A':
            stack = ['A']
        else:
            stack = []
     c input() input if len(stack) >= 2 and stack[-2:] == ["A", "B"] and c == 'C':
            ans += len(stack) - 1
            stack.pop()
        elif len(stack) >= 1 and stack[-1] == 'A' and c in ('A', 'B'):
            stack.append(c)
        elif c == 'A':
            stack = ['A']
        else:
            stack = []
     len(stack) >= 2 and stack[-2:] == ["A", "B"] and c == 'C' len(stack) >= 2 and stack[-2:] == ["A", "B"] len(stack) >= 2 len(stack) len stack 2 stack[-2:] == ["A", "B"] stack[-2:] stack -2: -2 ["A", "B"] "A" "B" c == 'C' c 'C' ans += len(stack) - 1 ans len(stack) - 1 len(stack) len stack 1 stack.pop() stack.pop stack pop elif len(stack) >= 1 and stack[-1] == 'A' and c in ('A', 'B'):
            stack.append(c)
         len(stack) >= 1 and stack[-1] == 'A' and c in ('A', 'B') len(stack) >= 1 and stack[-1] == 'A' len(stack) >= 1 len(stack) len stack 1 stack[-1] == 'A' stack[-1] stack -1 'A' c in ('A', 'B') c ('A', 'B') 'A' 'B' stack.append(c) stack.append stack append c elif c == 'A':
            stack = ['A']
         c == 'A' c 'A' stack = ['A'] stack ['A'] 'A' stack = [] stack [] print(ans) print ans resolve() resolve input = lambda:sys.stdin.readline().rstrip() lambda:sys.stdin.readline().rstrip() input INF = 1 << 60 1 << 60 INF MOD = 10**9 + 7 10**9 + 7 MOD def resolve():
    ans = 0
    stack = []
    for c in input():
        if len(stack) >= 2 and stack[-2:] == ["A", "B"] and c == 'C':
            ans += len(stack) - 1
            stack.pop()
        elif len(stack) >= 1 and stack[-1] == 'A' and c in ('A', 'B'):
            stack.append(c)
        elif c == 'A':
            stack = ['A']
        else:
            stack = []
    print(ans) def resolve():
    ans = 0
    stack = []
    for c in input():
        if len(stack) >= 2 and stack[-2:] == ["A", "B"] and c == 'C':
            ans += len(stack) - 1
            stack.pop()
        elif len(stack) >= 1 and stack[-1] == 'A' and c in ('A', 'B'):
            stack.append(c)
        elif c == 'A':
            stack = ['A']
        else:
            stack = []
    print(ans) resolve
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    ans = 0
    stack = []
    for c in input():
        if len(stack) >= 2 and stack[-2:] == ["A", "B"] and c == 'C':
            ans += len(stack) - 1
            stack.pop()
        elif len(stack) >= 1 and stack[-1] == 'A' and c in ('A', 'B'):
            stack.append(c)
        elif c == 'A':
            stack = ['A']
        else:
            stack = []
    print(ans)
resolve()