def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt, pi
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

S = input()
S = S.replace('BC', 'P')
N = len(S)

str_l = []
str_0 = ''
for i in range(N):
    if S[i] == "A" or S[i] == "P":
        str_0 += S[i]
    else:
        if str_0 != '':
            str_l.append(str_0)
            str_0 = ''
if str_0 != '':
    str_l.append(str_0)

ans = 0
for st in str_l:
    opt = []
    for i in range(len(st)):
        if st[i] == 'A':
            opt.append(0)
        else:
            opt.append(1)

    imos = copy.deepcopy(opt)
    for i in range(len(st) - 1):
        imos[-i - 2] += imos[-i - 1]

    for i in range(len(st)):
        if opt[i] == 0:
            ans += imos[i]
print(ans) def getN():
    return int(input()) getN return int(input()) int(input()) int input() input def getNM():
    return map(int, input().split()) getNM return map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split def getList():
    return list(map(int, input().split())) getList return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def getArray(intn):
    return [int(input()) for i in range(intn)] getArray int(input()) for i in range(intn) for i in range(intn) i range(intn) range intn for i in range(intn) int(input()) int input() input return [int(input()) for i in range(intn)] [int(input()) for i in range(intn)] intn intn def input():
    return sys.stdin.readline().rstrip() input return 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 rand_N(ran1, ran2):
    return random.randint(ran1, ran2) rand_N return random.randint(ran1, ran2) random.randint(ran1, ran2) random.randint random randint ran1 ran2 ran1 ran1 ran2 ran2 def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)] rand_List random.randint(ran1, ran2) for i in range(rantime) for i in range(rantime) i range(rantime) range rantime for i in range(rantime) random.randint(ran1, ran2) random.randint random randint ran1 ran2 return [random.randint(ran1, ran2) for i in range(rantime)] [random.randint(ran1, ran2) for i in range(rantime)] ran1 ran1 ran2 ran2 rantime rantime def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns) rand_ints_nodup ns = [] ns [] while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
   len(ns) < rantime len(ns) len ns rantime n = random.randint(ran1, ran2) n random.randint(ran1, ran2) random.randint random randint ran1 ran2 if not n in ns:
      ns.append(n)
   not n in ns n in ns n ns ns.append(n) ns.append ns append n return sorted(ns) sorted(ns) sorted ns ran1 ran1 ran2 ran2 rantime rantime def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query) rand_query r_query = [] r_query [] while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
   len(r_query) < rantime len(r_query) len r_query rantime n_q = rand_ints_nodup(ran1, ran2, 2) n_q rand_ints_nodup(ran1, ran2, 2) rand_ints_nodup ran1 ran2 2 if not n_q in r_query:
      r_query.append(n_q)
   not n_q in r_query n_q in r_query n_q r_query r_query.append(n_q) r_query.append r_query append n_q return sorted(r_query) sorted(r_query) sorted r_query ran1 ran1 ran2 ran2 rantime rantime from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq heapq from math import sqrt, pi from fractions import gcd import random random import string string import copy copy from itertools import combinations, permutations, product from operator import mul, itemgetter from functools import reduce from bisect import bisect_left, bisect_right import sys sys sys.setrecursionlimit(1000000000) sys.setrecursionlimit sys setrecursionlimit 1000000000 mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 S = input() S input() input S = S.replace('BC', 'P') S S.replace('BC', 'P') S.replace S replace 'BC' 'P' N = len(S) N len(S) len S str_l = [] str_l [] str_0 = '' str_0 '' for i in range(N):
    if S[i] == "A" or S[i] == "P":
        str_0 += S[i]
    else:
        if str_0 != '':
            str_l.append(str_0)
            str_0 = '' i range(N) range N if S[i] == "A" or S[i] == "P":
        str_0 += S[i]
    else:
        if str_0 != '':
            str_l.append(str_0)
            str_0 = '' S[i] == "A" or S[i] == "P" S[i] == "A" S[i] S i "A" S[i] == "P" S[i] S i "P" str_0 += S[i] str_0 S[i] S i if str_0 != '':
            str_l.append(str_0)
            str_0 = '' str_0 != '' str_0 '' str_l.append(str_0) str_l.append str_l append str_0 str_0 = '' str_0 '' if str_0 != '':
    str_l.append(str_0) str_0 != '' str_0 '' str_l.append(str_0) str_l.append str_l append str_0 ans = 0 ans 0 for st in str_l:
    opt = []
    for i in range(len(st)):
        if st[i] == 'A':
            opt.append(0)
        else:
            opt.append(1)

    imos = copy.deepcopy(opt)
    for i in range(len(st) - 1):
        imos[-i - 2] += imos[-i - 1]

    for i in range(len(st)):
        if opt[i] == 0:
            ans += imos[i] st str_l opt = [] opt [] for i in range(len(st)):
        if st[i] == 'A':
            opt.append(0)
        else:
            opt.append(1)

     i range(len(st)) range len(st) len st if st[i] == 'A':
            opt.append(0)
        else:
            opt.append(1)

     st[i] == 'A' st[i] st i 'A' opt.append(0) opt.append opt append 0 opt.append(1) opt.append opt append 1 imos = copy.deepcopy(opt) imos copy.deepcopy(opt) copy.deepcopy copy deepcopy opt for i in range(len(st) - 1):
        imos[-i - 2] += imos[-i - 1]

     i range(len(st) - 1) range len(st) - 1 len(st) len st 1 imos[-i - 2] += imos[-i - 1] imos[-i - 2] imos -i - 2 -i i 2 imos[-i - 1] imos -i - 1 -i i 1 for i in range(len(st)):
        if opt[i] == 0:
            ans += imos[i] i range(len(st)) range len(st) len st if opt[i] == 0:
            ans += imos[i] opt[i] == 0 opt[i] opt i 0 ans += imos[i] ans imos[i] imos i print(ans) print ans def getArray(intn):
    return [int(input()) for i in range(intn)] def getArray(intn):
    return [int(input()) for i in range(intn)] getArray str_0 = '' '' str_0 ans = 0 0 ans def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query) def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query) rand_query def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns) def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns) rand_ints_nodup S = input() input() S def rand_N(ran1, ran2):
    return random.randint(ran1, ran2) def rand_N(ran1, ran2):
    return random.randint(ran1, ran2) rand_N opt = [] [] opt S = S.replace('BC', 'P') S.replace('BC', 'P') S str_0 = '' '' str_0 def getN():
    return int(input()) def getN():
    return int(input()) getN def input():
    return sys.stdin.readline().rstrip() def input():
    return sys.stdin.readline().rstrip() input mod = 10 ** 9 + 7 10 ** 9 + 7 mod str_l = [] [] str_l ans += imos[i] imos[i] ans def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)] def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)] rand_List def getNM():
    return map(int, input().split()) def getNM():
    return map(int, input().split()) getNM imos = copy.deepcopy(opt) copy.deepcopy(opt) imos def getList():
    return list(map(int, input().split())) def getList():
    return list(map(int, input().split())) getList N = len(S) len(S) N str_0 += S[i] S[i] str_0
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt, pi
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

S = input()
S = S.replace('BC', 'P')
N = len(S)

str_l = []
str_0 = ''
for i in range(N):
    if S[i] == "A" or S[i] == "P":
        str_0 += S[i]
    else:
        if str_0 != '':
            str_l.append(str_0)
            str_0 = ''
if str_0 != '':
    str_l.append(str_0)

ans = 0
for st in str_l:
    opt = []
    for i in range(len(st)):
        if st[i] == 'A':
            opt.append(0)
        else:
            opt.append(1)

    imos = copy.deepcopy(opt)
    for i in range(len(st) - 1):
        imos[-i - 2] += imos[-i - 1]

    for i in range(len(st)):
        if opt[i] == 0:
            ans += imos[i]
print(ans)