from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
n = len(s)
ind = n-1
cnt = 0
res = 0
f = False
while ind >= 0:
    if ind-1 >= 0 and (s[ind-1],s[ind]) == ('B','C'):
        f = True
        cnt += 1
        ind -= 2
    elif f and s[ind] == 'A':
        res += cnt
        ind -= 1
    else:
        f = False
        cnt = 0
        ind -= 1
print(res) from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions sys bisect math itertools fractions sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 INF = float('inf') INF float('inf') float 'inf' def inp(): return int(sys.stdin.readline()) inp def inpl(): return list(map(int, sys.stdin.readline().split())) inpl s = input() s input() input n = len(s) n len(s) len s ind = n-1 ind n-1 n 1 cnt = 0 cnt 0 res = 0 res 0 f = False f False while ind >= 0:
    if ind-1 >= 0 and (s[ind-1],s[ind]) == ('B','C'):
        f = True
        cnt += 1
        ind -= 2
    elif f and s[ind] == 'A':
        res += cnt
        ind -= 1
    else:
        f = False
        cnt = 0
        ind -= 1 ind >= 0 ind 0 if ind-1 >= 0 and (s[ind-1],s[ind]) == ('B','C'):
        f = True
        cnt += 1
        ind -= 2
    elif f and s[ind] == 'A':
        res += cnt
        ind -= 1
    else:
        f = False
        cnt = 0
        ind -= 1 ind-1 >= 0 and (s[ind-1],s[ind]) == ('B','C') ind-1 >= 0 ind-1 ind 1 0 (s[ind-1],s[ind]) == ('B','C') (s[ind-1],s[ind]) s[ind-1] s ind-1 ind 1 s[ind] s ind ('B','C') 'B' 'C' f = True f True cnt += 1 cnt 1 ind -= 2 ind 2 elif f and s[ind] == 'A':
        res += cnt
        ind -= 1
     f and s[ind] == 'A' f s[ind] == 'A' s[ind] s ind 'A' res += cnt res cnt ind -= 1 ind 1 f = False f False cnt = 0 cnt 0 ind -= 1 ind 1 print(res) print res cnt = 0 0 cnt cnt = 0 0 cnt def inp(): return int(sys.stdin.readline()) def inp(): return int(sys.stdin.readline()) inp n = len(s) len(s) n f = False False f res = 0 0 res ind -= 1 1 ind s = input() input() s mod = 10**9+7 10**9+7 mod f = False False f ind -= 1 1 ind ind = n-1 n-1 ind cnt += 1 1 cnt def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl(): return list(map(int, sys.stdin.readline().split())) inpl ind -= 2 2 ind INF = float('inf') float('inf') INF res += cnt cnt res f = True True f
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
n = len(s)
ind = n-1
cnt = 0
res = 0
f = False
while ind >= 0:
    if ind-1 >= 0 and (s[ind-1],s[ind]) == ('B','C'):
        f = True
        cnt += 1
        ind -= 2
    elif f and s[ind] == 'A':
        res += cnt
        ind -= 1
    else:
        f = False
        cnt = 0
        ind -= 1
print(res)
