# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def run():
    S = input()
    SS = []
    dic = {'A': -1, 'B' : -2, 'C' : -3}
    chain = False
    skip = False
    for i in range(len(S)):
        if not chain:
            if S[i:i+2] == 'BC':
                chain = True
                skip = True
                SS.append(1)
            else:
                SS.append(dic[S[i]])
        else:
            if skip:
                skip = False
                continue
            else:
                if S[i:i+2] == 'BC':
                    skip = True
                    SS[-1] += 1
                else:
                    SS.append(dic[S[i]])
                    chain = skip = False
    #print(SS)
    ans = 0
    BCbox = 0
    for x in SS[::-1]:
        if x > 0:
            BCbox += x
        elif x == -1:
            ans += BCbox
        else:
            BCbox = 0
    print(ans)



if __name__ == "__main__":
    run() import sys sys sysread = sys.stdin.buffer.readline sysread sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 INF = 1 << 50 INF 1 << 50 1 50 EPS = 1e-8 EPS 1e-8 mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 def run():
    S = input()
    SS = []
    dic = {'A': -1, 'B' : -2, 'C' : -3}
    chain = False
    skip = False
    for i in range(len(S)):
        if not chain:
            if S[i:i+2] == 'BC':
                chain = True
                skip = True
                SS.append(1)
            else:
                SS.append(dic[S[i]])
        else:
            if skip:
                skip = False
                continue
            else:
                if S[i:i+2] == 'BC':
                    skip = True
                    SS[-1] += 1
                else:
                    SS.append(dic[S[i]])
                    chain = skip = False
    #print(SS)
    ans = 0
    BCbox = 0
    for x in SS[::-1]:
        if x > 0:
            BCbox += x
        elif x == -1:
            ans += BCbox
        else:
            BCbox = 0
    print(ans) run S = input() S input() input SS = [] SS [] dic = {'A': -1, 'B' : -2, 'C' : -3} dic {'A': -1, 'B' : -2, 'C' : -3} 'A' 'A' -1 'B' 'B' -2 'C' 'C' -3 chain = False chain False skip = False skip False for i in range(len(S)):
        if not chain:
            if S[i:i+2] == 'BC':
                chain = True
                skip = True
                SS.append(1)
            else:
                SS.append(dic[S[i]])
        else:
            if skip:
                skip = False
                continue
            else:
                if S[i:i+2] == 'BC':
                    skip = True
                    SS[-1] += 1
                else:
                    SS.append(dic[S[i]])
                    chain = skip = False
    #print(SS)
     i range(len(S)) range len(S) len S if not chain:
            if S[i:i+2] == 'BC':
                chain = True
                skip = True
                SS.append(1)
            else:
                SS.append(dic[S[i]])
        else:
            if skip:
                skip = False
                continue
            else:
                if S[i:i+2] == 'BC':
                    skip = True
                    SS[-1] += 1
                else:
                    SS.append(dic[S[i]])
                    chain = skip = False
    #print(SS)
     not chain chain if S[i:i+2] == 'BC':
                chain = True
                skip = True
                SS.append(1)
            else:
                SS.append(dic[S[i]])
         S[i:i+2] == 'BC' S[i:i+2] S i:i+2 i i+2 i 2 'BC' chain = True chain True skip = True skip True SS.append(1) SS.append SS append 1 SS.append(dic[S[i]]) SS.append SS append dic[S[i]] dic S[i] S i if skip:
                skip = False
                continue
            else:
                if S[i:i+2] == 'BC':
                    skip = True
                    SS[-1] += 1
                else:
                    SS.append(dic[S[i]])
                    chain = skip = False
    #print(SS)
     skip skip = False skip False continue if S[i:i+2] == 'BC':
                    skip = True
                    SS[-1] += 1
                else:
                    SS.append(dic[S[i]])
                    chain = skip = False
    #print(SS)
     S[i:i+2] == 'BC' S[i:i+2] S i:i+2 i i+2 i 2 'BC' skip = True skip True SS[-1] += 1 SS[-1] SS -1 1 SS.append(dic[S[i]]) SS.append SS append dic[S[i]] dic S[i] S i chain = skip = False chain False = skip = False skip False ans = 0 ans 0 BCbox = 0 BCbox 0 for x in SS[::-1]:
        if x > 0:
            BCbox += x
        elif x == -1:
            ans += BCbox
        else:
            BCbox = 0
     x SS[::-1] SS ::-1 -1 if x > 0:
            BCbox += x
        elif x == -1:
            ans += BCbox
        else:
            BCbox = 0
     x > 0 x 0 BCbox += x BCbox x elif x == -1:
            ans += BCbox
         x == -1 x -1 ans += BCbox ans BCbox BCbox = 0 BCbox 0 print(ans) print ans if __name__ == "__main__":
    run() __name__ == "__main__" __name__ "__main__" run() run def run():
    S = input()
    SS = []
    dic = {'A': -1, 'B' : -2, 'C' : -3}
    chain = False
    skip = False
    for i in range(len(S)):
        if not chain:
            if S[i:i+2] == 'BC':
                chain = True
                skip = True
                SS.append(1)
            else:
                SS.append(dic[S[i]])
        else:
            if skip:
                skip = False
                continue
            else:
                if S[i:i+2] == 'BC':
                    skip = True
                    SS[-1] += 1
                else:
                    SS.append(dic[S[i]])
                    chain = skip = False
    #print(SS)
    ans = 0
    BCbox = 0
    for x in SS[::-1]:
        if x > 0:
            BCbox += x
        elif x == -1:
            ans += BCbox
        else:
            BCbox = 0
    print(ans) def run():
    S = input()
    SS = []
    dic = {'A': -1, 'B' : -2, 'C' : -3}
    chain = False
    skip = False
    for i in range(len(S)):
        if not chain:
            if S[i:i+2] == 'BC':
                chain = True
                skip = True
                SS.append(1)
            else:
                SS.append(dic[S[i]])
        else:
            if skip:
                skip = False
                continue
            else:
                if S[i:i+2] == 'BC':
                    skip = True
                    SS[-1] += 1
                else:
                    SS.append(dic[S[i]])
                    chain = skip = False
    #print(SS)
    ans = 0
    BCbox = 0
    for x in SS[::-1]:
        if x > 0:
            BCbox += x
        elif x == -1:
            ans += BCbox
        else:
            BCbox = 0
    print(ans) run mod = 10 ** 9 + 7 10 ** 9 + 7 mod INF = 1 << 50 1 << 50 INF EPS = 1e-8 1e-8 EPS sysread = sys.stdin.buffer.readline sys.stdin.buffer.readline sysread read = sys.stdin.buffer.read sys.stdin.buffer.read read
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def run():
    S = input()
    SS = []
    dic = {'A': -1, 'B' : -2, 'C' : -3}
    chain = False
    skip = False
    for i in range(len(S)):
        if not chain:
            if S[i:i+2] == 'BC':
                chain = True
                skip = True
                SS.append(1)
            else:
                SS.append(dic[S[i]])
        else:
            if skip:
                skip = False
                continue
            else:
                if S[i:i+2] == 'BC':
                    skip = True
                    SS[-1] += 1
                else:
                    SS.append(dic[S[i]])
                    chain = skip = False
    #print(SS)
    ans = 0
    BCbox = 0
    for x in SS[::-1]:
        if x > 0:
            BCbox += x
        elif x == -1:
            ans += BCbox
        else:
            BCbox = 0
    print(ans)



if __name__ == "__main__":
    run()
