from _collections import deque


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
import scipy
from collections import deque
from math import sqrt
from math import floor
#https://atcoder.jp/contests/agc034/tasks/agc034_b
#B - ABC 
"""
need to consider the case that ticket is not enough to lower everything
"""


def cost(d):
    tc = 0
    d_cnt = 0
    for c in d:
        if c == 'D':
            tc += d_cnt
        else:
            d_cnt += 1

    return tc


s = gw()
d = []
i = 0
ans = 0
while i < len(s):
    if (s[i] == 'A'):
        d.append(s[i])
        i += 1
    elif (s[i] == 'B' and (i + 1) < len(s) and s[i + 1] == 'C'):
        d.append('D')
        i += 2
    else:
        ans += cost(d)
        d = []
        i += 1

ans += cost(d)

print(ans) from _collections import deque def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number) parser while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number) 1 data = list(input().split(' ')) data list(input().split(' ')) list input().split(' ') ().split () input split ' ' for number in data:
            if len(number) > 0:
                yield (number) number data if len(number) > 0:
                yield (number) len(number) > 0 len(number) len number 0 yield (number) number input_parser = parser() input_parser parser() parser def gw():
    global input_parser
    return next(input_parser) gw global input_parser return next(input_parser) next(input_parser) next input_parser def gi():
    data = gw()
    return int(data) gi data = gw() data gw() gw return int(data) int(data) int data MOD = int(1e9 + 7) MOD int(1e9 + 7) int 1e9 + 7 1e9 7 import numpy numpy import scipy scipy from collections import deque from math import sqrt from math import floor """
need to consider the case that ticket is not enough to lower everything
""" def cost(d):
    tc = 0
    d_cnt = 0
    for c in d:
        if c == 'D':
            tc += d_cnt
        else:
            d_cnt += 1

    return tc cost tc = 0 tc 0 d_cnt = 0 d_cnt 0 for c in d:
        if c == 'D':
            tc += d_cnt
        else:
            d_cnt += 1

     c d if c == 'D':
            tc += d_cnt
        else:
            d_cnt += 1

     c == 'D' c 'D' tc += d_cnt tc d_cnt d_cnt += 1 d_cnt 1 return tc tc d d s = gw() s gw() gw d = [] d [] i = 0 i 0 ans = 0 ans 0 while i < len(s):
    if (s[i] == 'A'):
        d.append(s[i])
        i += 1
    elif (s[i] == 'B' and (i + 1) < len(s) and s[i + 1] == 'C'):
        d.append('D')
        i += 2
    else:
        ans += cost(d)
        d = []
        i += 1 i < len(s) i len(s) len s if (s[i] == 'A'):
        d.append(s[i])
        i += 1
    elif (s[i] == 'B' and (i + 1) < len(s) and s[i + 1] == 'C'):
        d.append('D')
        i += 2
    else:
        ans += cost(d)
        d = []
        i += 1 s[i] == 'A' s[i] s i 'A' d.append(s[i]) d.append d append s[i] s i i += 1 i 1 elif (s[i] == 'B' and (i + 1) < len(s) and s[i + 1] == 'C'):
        d.append('D')
        i += 2
     s[i] == 'B' and (i + 1) < len(s) and s[i + 1] == 'C' s[i] == 'B' and (i + 1) < len(s) s[i] == 'B' s[i] s i 'B' (i + 1) < len(s) i + 1 i 1 len(s) len s s[i + 1] == 'C' s[i + 1] s i + 1 i 1 'C' d.append('D') d.append d append 'D' i += 2 i 2 ans += cost(d) ans cost(d) cost d d = [] d [] i += 1 i 1 ans += cost(d) ans cost(d) cost d print(ans) print ans s = gw() gw() s i = 0 0 i MOD = int(1e9 + 7) int(1e9 + 7) MOD i += 2 2 i d = [] [] d input_parser = parser() parser() input_parser def cost(d):
    tc = 0
    d_cnt = 0
    for c in d:
        if c == 'D':
            tc += d_cnt
        else:
            d_cnt += 1

    return tc def cost(d):
    tc = 0
    d_cnt = 0
    for c in d:
        if c == 'D':
            tc += d_cnt
        else:
            d_cnt += 1

    return tc cost ans = 0 0 ans ans += cost(d) cost(d) ans d = [] [] d def gi():
    data = gw()
    return int(data) def gi():
    data = gw()
    return int(data) gi i += 1 1 i def gw():
    global input_parser
    return next(input_parser) def gw():
    global input_parser
    return next(input_parser) gw i += 1 1 i ans += cost(d) cost(d) ans def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number) def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number) parser
from _collections import deque


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
import scipy
from collections import deque
from math import sqrt
from math import floor
#https://atcoder.jp/contests/agc034/tasks/agc034_b
#B - ABC 
"""
need to consider the case that ticket is not enough to lower everything
"""


def cost(d):
    tc = 0
    d_cnt = 0
    for c in d:
        if c == 'D':
            tc += d_cnt
        else:
            d_cnt += 1

    return tc


s = gw()
d = []
i = 0
ans = 0
while i < len(s):
    if (s[i] == 'A'):
        d.append(s[i])
        i += 1
    elif (s[i] == 'B' and (i + 1) < len(s) and s[i + 1] == 'C'):
        d.append('D')
        i += 2
    else:
        ans += cost(d)
        d = []
        i += 1

ans += cost(d)

print(ans)
