s = eval(input())

stock_bc = 0

state = 0

ans = 0



for i in range(len(s)):



    if s[-1-i] == "C":

        if state == 1:

            stock_bc = 0

        state = 1



    elif s[-1-i] == "B":

        if state == 0:

            stock_bc = 0

        elif state == 1:

            stock_bc += 1

        state = 0



    elif s[-1-i] == "A":

        if state == 0:

            ans += stock_bc

        else:

            stock_bc = 0

            state = 2



print(ans)
s = eval(input())

s2 = s.replace("BC", "D")



A, ans = 0, 0



for i in s2:

    if i == "A":

        A += 1

    elif i == "D":

        ans += A

    else:

        A = 0



print(ans)
s = eval(input())
stock_bc = 0
state = 0
ans = 0
for i in range(len(s)):
    if s[-1 - i] == "C":
        if state == 1:
            stock_bc = 0
        state = 1
    elif s[-1 - i] == "B":
        if state == 0:
            stock_bc = 0
        elif state == 1:
            stock_bc += 1
        state = 0
    elif s[-1 - i] == "A":
        if state == 0:
            ans += stock_bc
        else:
            stock_bc = 0
            state = 2
print(ans)

s = eval(input())
s2 = s.replace("BC", "D")
A, ans = 0, 0
for i in s2:
    if i == "A":
        A += 1
    elif i == "D":
        ans += A
    else:
        A = 0
print(ans)

-stock_bc = 0 -state = 0 -ans = 0 -for i in range(len(s)): -    if s[-1 - i] == "C": -        if state == 1: -            stock_bc = 0 -        state = 1 -    elif s[-1 - i] == "B": -        if state == 0: -            stock_bc = 0 -        elif state == 1: -            stock_bc += 1 -        state = 0 -    elif s[-1 - i] == "A": -        if state == 0: -            ans += stock_bc -        else: -            stock_bc = 0 -            state = 2 +s2 = s.replace("BC", "D") +A, ans = 0, 0 +for i in s2: +    if i == "A": +        A += 1 +    elif i == "D": +        ans += A +    else: +        A = 0