s = eval(input())



ans = 0

a = 0

b = 0

for i in range(len(s)):

    if s[i] == 'A':

        if b > 0:

            a = 1

            b = 0

        elif b == 0:

            a += 1

            b = 0

    if s[i] == 'B':

        if a > 0 and b == 0:

            b += 1

        elif b > 0:

            a = 0

            b = 0

    if s[i] == 'C':

        if b > 0:

            ans += a

            b = 0

        elif b == 0:

            a = 0

            b = 0

print(ans)

from functools import reduce



# 入力

s = eval(input())



# AA..ABC -> BCAA..A に変換するのを繰り返す

ans, _, _ = reduce(

    lambda acc, c: (

        (acc[0], (1 - acc[2]) * acc[1] + 1, 0) if c == 'A' else

        (acc[0], (1 - acc[2]) * acc[1], 1 - acc[2]) if c == 'B' else

        (acc[0] + acc[2] * acc[1], acc[2] * acc[1], 0)

    ),

    s,

    (0, 0, 0)

)



# 出力

print(ans)

s = eval(input())
ans = 0
a = 0
b = 0
for i in range(len(s)):
    if s[i] == "A":
        if b > 0:
            a = 1
            b = 0
        elif b == 0:
            a += 1
            b = 0
    if s[i] == "B":
        if a > 0 and b == 0:
            b += 1
        elif b > 0:
            a = 0
            b = 0
    if s[i] == "C":
        if b > 0:
            ans += a
            b = 0
        elif b == 0:
            a = 0
            b = 0
print(ans)

from functools import reduce

# 入力
s = eval(input())
# AA..ABC -> BCAA..A に変換するのを繰り返す
ans, _, _ = reduce(
    lambda acc, c: (
        (acc[0], (1 - acc[2]) * acc[1] + 1, 0)
        if c == "A"
        else (acc[0], (1 - acc[2]) * acc[1], 1 - acc[2])
        if c == "B"
        else (acc[0] + acc[2] * acc[1], acc[2] * acc[1], 0)
    ),
    s,
    (0, 0, 0),
)
# 出力
print(ans)

+from functools import reduce + +# 入力 -ans = 0 -a = 0 -b = 0 -for i in range(len(s)): -    if s[i] == "A": -        if b > 0: -            a = 1 -            b = 0 -        elif b == 0: -            a += 1 -            b = 0 -    if s[i] == "B": -        if a > 0 and b == 0: -            b += 1 -        elif b > 0: -            a = 0 -            b = 0 -    if s[i] == "C": -        if b > 0: -            ans += a -            b = 0 -        elif b == 0: -            a = 0 -            b = 0 +# AA..ABC -> BCAA..A に変換するのを繰り返す +ans, _, _ = reduce( +    lambda acc, c: ( +        (acc[0], (1 - acc[2]) * acc[1] + 1, 0) +        if c == "A" +        else (acc[0], (1 - acc[2]) * acc[1], 1 - acc[2]) +        if c == "B" +        else (acc[0] + acc[2] * acc[1], acc[2] * acc[1], 0) +    ), +    s, +    (0, 0, 0), +) +# 出力