# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

s = input()
ss = []
ind = 0
while ind < len(s)-1:
    if s[ind] == 'B' and s[ind+1] == 'C':
        ss.append('D')
        ind+=2
    else:
        ss.append(s[ind])
        ind+=1
if ind == len(s)-1:
    ss.append(s[ind])
ind = 0
A = 0
ans = 0
while ind < len(ss):
    if ss[ind] == 'A':
        A+=1
    elif ss[ind] == 'D':
        ans+=A
    else:
        A = 0
    ind+=1
print(ans) import math math import fractions fractions import sys sys import bisect bisect import heapq heapq import collections collections from collections import Counter from collections import deque import pprint pprint sr = lambda: input() sr lambda: input() input() input ir = lambda: int(sr()) ir lambda: int(sr()) int(sr()) int sr() sr lr = lambda: list(map(int, sr().split())) lr lambda: list(map(int, sr().split())) list(map(int, sr().split())) list map(int, sr().split()) map int sr().split() ().split () sr split """nを素因数分解""" """2以上の整数n => [[素因数, 指数], ...]の2次元リスト""" def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n factorization arr = [] arr [] temp = n temp n if n == 1:
        return arr

     n == 1 n 1 return arr arr for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

     i range(2, int(-(-n**0.5//1))+1) range 2 int(-(-n**0.5//1))+1 int(-(-n**0.5//1)) int -(-n**0.5//1) -n**0.5//1 -n**0.5 n**0.5 n 0.5 1 1 if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

     temp%i==0 temp%i temp i 0 cnt=0 cnt 0 while temp%i==0:
                cnt+=1
                temp //= i
             temp%i==0 temp%i temp i 0 cnt+=1 cnt 1 temp //= i temp i arr.append([i, cnt]) arr.append arr append [i, cnt] i cnt if temp!=1:
        arr.append([temp, 1])

     temp!=1 temp 1 arr.append([temp, 1]) arr.append arr append [temp, 1] temp 1 if arr==[]:
        arr.append([n, 1])

     arr==[] arr [] arr.append([n, 1]) arr.append arr append [n, 1] n 1 return arr arr n n def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l power x = 1 x 1 while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
     n if n & 1:
            x *= a % mod
         n & 1 n 1 x *= a % mod x a % mod a mod n >>= 1 n 1 a *= a % mod a a % mod a mod return x % mod x % mod x mod a a n n mod mod def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a kaijo if n == 0:
        return 1
     n == 0 n 0 return 1 1 a = n a n tmp = n-1 tmp n-1 n 1 while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
     tmp >= l tmp l a = a*tmp%mod a a*tmp%mod a*tmp a tmp mod tmp -= 1 tmp 1 return a a n n l l mod mod inf = 10**18 inf 10**18 10 18 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 s = input() s input() input ss = [] ss [] ind = 0 ind 0 while ind < len(s)-1:
    if s[ind] == 'B' and s[ind+1] == 'C':
        ss.append('D')
        ind+=2
    else:
        ss.append(s[ind])
        ind+=1 ind < len(s)-1 ind len(s)-1 len(s) len s 1 if s[ind] == 'B' and s[ind+1] == 'C':
        ss.append('D')
        ind+=2
    else:
        ss.append(s[ind])
        ind+=1 s[ind] == 'B' and s[ind+1] == 'C' s[ind] == 'B' s[ind] s ind 'B' s[ind+1] == 'C' s[ind+1] s ind+1 ind 1 'C' ss.append('D') ss.append ss append 'D' ind+=2 ind 2 ss.append(s[ind]) ss.append ss append s[ind] s ind ind+=1 ind 1 if ind == len(s)-1:
    ss.append(s[ind]) ind == len(s)-1 ind len(s)-1 len(s) len s 1 ss.append(s[ind]) ss.append ss append s[ind] s ind ind = 0 ind 0 A = 0 A 0 ans = 0 ans 0 while ind < len(ss):
    if ss[ind] == 'A':
        A+=1
    elif ss[ind] == 'D':
        ans+=A
    else:
        A = 0
    ind+=1 ind < len(ss) ind len(ss) len ss if ss[ind] == 'A':
        A+=1
    elif ss[ind] == 'D':
        ans+=A
    else:
        A = 0
     ss[ind] == 'A' ss[ind] ss ind 'A' A+=1 A 1 elif ss[ind] == 'D':
        ans+=A
     ss[ind] == 'D' ss[ind] ss ind 'D' ans+=A ans A A = 0 A 0 ind+=1 ind 1 print(ans) print ans ind = 0 0 ind ss = [] [] ss mod = 10**9+7 10**9+7 mod ind+=1 1 ind lr = lambda: list(map(int, sr().split())) lambda: list(map(int, sr().split())) lr ans = 0 0 ans A+=1 1 A A = 0 0 A def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a kaijo A = 0 0 A ind+=1 1 ind def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l power s = input() input() s ind = 0 0 ind sr = lambda: input() lambda: input() sr def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n factorization ind+=2 2 ind ir = lambda: int(sr()) lambda: int(sr()) ir ans+=A A ans inf = 10**18 10**18 inf
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

s = input()
ss = []
ind = 0
while ind < len(s)-1:
    if s[ind] == 'B' and s[ind+1] == 'C':
        ss.append('D')
        ind+=2
    else:
        ss.append(s[ind])
        ind+=1
if ind == len(s)-1:
    ss.append(s[ind])
ind = 0
A = 0
ans = 0
while ind < len(ss):
    if ss[ind] == 'A':
        A+=1
    elif ss[ind] == 'D':
        ans+=A
    else:
        A = 0
    ind+=1
print(ans)