import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

s = input()
s = s.replace('BC', 'D')
s_list = s.split("B")
x = []
for e in s_list:
    x += e.split("C")

ans = 0
for e in x:
    cnt_d = 0
    now = 0
    for c in e[::-1]:
        if c == 'D':
            cnt_d += 1
        if c == 'A':
            now += cnt_d
    ans += now
print(ans)
        
 import sys sys import itertools itertools import time time import math math import heapq heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 INF = 10 ** 18 INF 10 ** 18 10 18 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines s = input() s input() input s = s.replace('BC', 'D') s s.replace('BC', 'D') s.replace s replace 'BC' 'D' s_list = s.split("B") s_list s.split("B") s.split s split "B" x = [] x [] for e in s_list:
    x += e.split("C") e s_list x += e.split("C") x e.split("C") e.split e split "C" ans = 0 ans 0 for e in x:
    cnt_d = 0
    now = 0
    for c in e[::-1]:
        if c == 'D':
            cnt_d += 1
        if c == 'A':
            now += cnt_d
    ans += now e x cnt_d = 0 cnt_d 0 now = 0 now 0 for c in e[::-1]:
        if c == 'D':
            cnt_d += 1
        if c == 'A':
            now += cnt_d
     c e[::-1] e ::-1 -1 if c == 'D':
            cnt_d += 1
         c == 'D' c 'D' cnt_d += 1 cnt_d 1 if c == 'A':
            now += cnt_d
     c == 'A' c 'A' now += cnt_d now cnt_d ans += now ans now print(ans) print ans s = input() input() s now = 0 0 now cnt_d += 1 1 cnt_d readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD x = [] [] x readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines s = s.replace('BC', 'D') s.replace('BC', 'D') s s_list = s.split("B") s.split("B") s_list cnt_d = 0 0 cnt_d now += cnt_d cnt_d now INF = 10 ** 18 10 ** 18 INF ans = 0 0 ans ans += now now ans read = sys.stdin.buffer.read sys.stdin.buffer.read read x += e.split("C") e.split("C") x
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

s = input()
s = s.replace('BC', 'D')
s_list = s.split("B")
x = []
for e in s_list:
    x += e.split("C")

ans = 0
for e in x:
    cnt_d = 0
    now = 0
    for c in e[::-1]:
        if c == 'D':
            cnt_d += 1
        if c == 'A':
            now += cnt_d
    ans += now
print(ans)
        

