import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

s = STR()
a = []
i = 0
while i < len(s):
    if s[i] == 'A':
        a.append(0)
        i += 1
    elif i < len(s) - 1 and s[i:i + 2] == 'BC':
        a.append(1)
        i += 2
    else:
        a.append(2)
        i += 1
debug(a)
arr = []
bgn = -1
end = -1
for i in range(len(a)):
    if bgn == -1 and a[i] != 2:
        bgn = i
    if a[i] == 2 and end == -1:
        end = i
        arr.append(a[bgn:end])
        bgn = -1
        end = -1
arr.append(a[bgn:len(a) + 1])
debug(arr)
ans = 0
for b in arr:
    num0 = 0
    for i in b:
        if i == 0:
            num0 += 1
        if i == 1:
            ans += num0
print(ans) import sys, re, os sys re os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10 from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def debug(*args):
    if debugmode:
        print(*args) debug if debugmode:
        print(*args) debugmode print(*args) print *args args *args def input(): return sys.stdin.readline().strip() input def STR(): return input() STR def INT(): return int(input()) INT def FLOAT(): return float(input()) FLOAT def MAP(): return map(int, input().split()) MAP def S_MAP(): return map(str, input().split()) S_MAP def LIST(): return list(map(int, input().split())) LIST def S_LIST(): return list(map(str, input().split())) S_LIST def lcm(a, b): return a * b // gcd(a, b) lcm a a b b sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 inf = sys.maxsize inf sys.maxsize sys maxsize mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 dx = [0, 0, 1, -1, 1, -1, -1, 1] dx [0, 0, 1, -1, 1, -1, -1, 1] 0 0 1 -1 1 -1 -1 1 dy = [1, -1, 0, 0, 1, -1, 1, -1] dy [1, -1, 0, 0, 1, -1, 1, -1] 1 -1 0 0 1 -1 1 -1 debugmode = False debugmode False s = STR() s STR() STR a = [] a [] i = 0 i 0 while i < len(s):
    if s[i] == 'A':
        a.append(0)
        i += 1
    elif i < len(s) - 1 and s[i:i + 2] == 'BC':
        a.append(1)
        i += 2
    else:
        a.append(2)
        i += 1 i < len(s) i len(s) len s if s[i] == 'A':
        a.append(0)
        i += 1
    elif i < len(s) - 1 and s[i:i + 2] == 'BC':
        a.append(1)
        i += 2
    else:
        a.append(2)
        i += 1 s[i] == 'A' s[i] s i 'A' a.append(0) a.append a append 0 i += 1 i 1 elif i < len(s) - 1 and s[i:i + 2] == 'BC':
        a.append(1)
        i += 2
     i < len(s) - 1 and s[i:i + 2] == 'BC' i < len(s) - 1 i len(s) - 1 len(s) len s 1 s[i:i + 2] == 'BC' s[i:i + 2] s i:i + 2 i i + 2 i 2 'BC' a.append(1) a.append a append 1 i += 2 i 2 a.append(2) a.append a append 2 i += 1 i 1 debug(a) debug a arr = [] arr [] bgn = -1 bgn -1 end = -1 end -1 for i in range(len(a)):
    if bgn == -1 and a[i] != 2:
        bgn = i
    if a[i] == 2 and end == -1:
        end = i
        arr.append(a[bgn:end])
        bgn = -1
        end = -1 i range(len(a)) range len(a) len a if bgn == -1 and a[i] != 2:
        bgn = i
     bgn == -1 and a[i] != 2 bgn == -1 bgn -1 a[i] != 2 a[i] a i 2 bgn = i bgn i if a[i] == 2 and end == -1:
        end = i
        arr.append(a[bgn:end])
        bgn = -1
        end = -1 a[i] == 2 and end == -1 a[i] == 2 a[i] a i 2 end == -1 end -1 end = i end i arr.append(a[bgn:end]) arr.append arr append a[bgn:end] a bgn:end bgn end bgn = -1 bgn -1 end = -1 end -1 arr.append(a[bgn:len(a) + 1]) arr.append arr append a[bgn:len(a) + 1] a bgn:len(a) + 1 bgn len(a) + 1 len(a) len a 1 debug(arr) debug arr ans = 0 ans 0 for b in arr:
    num0 = 0
    for i in b:
        if i == 0:
            num0 += 1
        if i == 1:
            ans += num0 b arr num0 = 0 num0 0 for i in b:
        if i == 0:
            num0 += 1
        if i == 1:
            ans += num0 i b if i == 0:
            num0 += 1
         i == 0 i 0 num0 += 1 num0 1 if i == 1:
            ans += num0 i == 1 i 1 ans += num0 ans num0 print(ans) print ans def STR(): return input() def STR(): return input() STR dy = [1, -1, 0, 0, 1, -1, 1, -1] [1, -1, 0, 0, 1, -1, 1, -1] dy debugmode = False False debugmode ans = 0 0 ans arr = [] [] arr def INT(): return int(input()) def INT(): return int(input()) INT i = 0 0 i num0 += 1 1 num0 num0 = 0 0 num0 def debug(*args):
    if debugmode:
        print(*args) def debug(*args):
    if debugmode:
        print(*args) debug i += 2 2 i bgn = i i bgn def S_LIST(): return list(map(str, input().split())) def S_LIST(): return list(map(str, input().split())) S_LIST inf = sys.maxsize sys.maxsize inf i += 1 1 i end = i i end end = -1 -1 end def MAP(): return map(int, input().split()) def MAP(): return map(int, input().split()) MAP bgn = -1 -1 bgn ans += num0 num0 ans def S_MAP(): return map(str, input().split()) def S_MAP(): return map(str, input().split()) S_MAP bgn = -1 -1 bgn dx = [0, 0, 1, -1, 1, -1, -1, 1] [0, 0, 1, -1, 1, -1, -1, 1] dx mod = 10 ** 9 + 7 10 ** 9 + 7 mod i += 1 1 i def lcm(a, b): return a * b // gcd(a, b) def lcm(a, b): return a * b // gcd(a, b) lcm end = -1 -1 end a = [] [] a def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input def FLOAT(): return float(input()) def FLOAT(): return float(input()) FLOAT s = STR() STR() s def LIST(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) LIST
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

s = STR()
a = []
i = 0
while i < len(s):
    if s[i] == 'A':
        a.append(0)
        i += 1
    elif i < len(s) - 1 and s[i:i + 2] == 'BC':
        a.append(1)
        i += 2
    else:
        a.append(2)
        i += 1
debug(a)
arr = []
bgn = -1
end = -1
for i in range(len(a)):
    if bgn == -1 and a[i] != 2:
        bgn = i
    if a[i] == 2 and end == -1:
        end = i
        arr.append(a[bgn:end])
        bgn = -1
        end = -1
arr.append(a[bgn:len(a) + 1])
debug(arr)
ans = 0
for b in arr:
    num0 = 0
    for i in b:
        if i == 0:
            num0 += 1
        if i == 1:
            ans += num0
print(ans)
