from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
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()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
res = 0
bc = 0
i = n-1
while i >= 0:
    if s[i] == 'A':
        res += bc
        i -= 1
    elif i != 0 and s[i-1] == 'B' and s[i] == 'C':
        bc += 1
        i -= 2
    else:
        bc = 0
        i -= 1
print(res) from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys bisect math itertools fractions pprint 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 def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) inpln n n s = input() s input() input n = len(s) n len(s) len s res = 0 res 0 bc = 0 bc 0 i = n-1 i n-1 n 1 while i >= 0:
    if s[i] == 'A':
        res += bc
        i -= 1
    elif i != 0 and s[i-1] == 'B' and s[i] == 'C':
        bc += 1
        i -= 2
    else:
        bc = 0
        i -= 1 i >= 0 i 0 if s[i] == 'A':
        res += bc
        i -= 1
    elif i != 0 and s[i-1] == 'B' and s[i] == 'C':
        bc += 1
        i -= 2
    else:
        bc = 0
        i -= 1 s[i] == 'A' s[i] s i 'A' res += bc res bc i -= 1 i 1 elif i != 0 and s[i-1] == 'B' and s[i] == 'C':
        bc += 1
        i -= 2
     i != 0 and s[i-1] == 'B' and s[i] == 'C' i != 0 and s[i-1] == 'B' i != 0 i 0 s[i-1] == 'B' s[i-1] s i-1 i 1 'B' s[i] == 'C' s[i] s i 'C' bc += 1 bc 1 i -= 2 i 2 bc = 0 bc 0 i -= 1 i 1 print(res) print res bc = 0 0 bc mod = 10**9+7 10**9+7 mod i -= 1 1 i i -= 2 2 i s = input() input() s i = n-1 n-1 i bc += 1 1 bc i -= 1 1 i res += bc bc res res = 0 0 res bc = 0 0 bc n = len(s) len(s) n INF = float('inf') float('inf') INF def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) inpln def inp(): return int(sys.stdin.readline()) def inp(): return int(sys.stdin.readline()) inp def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl(): return list(map(int, sys.stdin.readline().split())) inpl
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
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()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
res = 0
bc = 0
i = n-1
while i >= 0:
    if s[i] == 'A':
        res += bc
        i -= 1
    elif i != 0 and s[i-1] == 'B' and s[i] == 'C':
        bc += 1
        i -= 2
    else:
        bc = 0
        i -= 1
print(res)