S = eval(input())

S = S.replace('BC', 'D').replace('B', ' ').replace('C', ' ').split()



ans = 0

for s in S:

    leftA = 0

    for i, t in enumerate(s[:: -1]):

        if t == 'A':

            ans += max(0, i - leftA)

            leftA += 1



print(ans)
S = eval(input())

S = S.replace('BC', 'D')



cnt = 0

ans = 0

for i, s in enumerate(S):

    if s == 'D':

        ans += cnt

    elif s == 'A':

        cnt += 1

    else:

        cnt = 0

print(ans)

S = eval(input())
S = S.replace("BC", "D").replace("B", " ").replace("C", " ").split()
ans = 0
for s in S:
    leftA = 0
    for i, t in enumerate(s[::-1]):
        if t == "A":
            ans += max(0, i - leftA)
            leftA += 1
print(ans)

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

-S = S.replace("BC", "D").replace("B", " ").replace("C", " ").split() +S = S.replace("BC", "D") +cnt = 0 -for s in S: -    leftA = 0 -    for i, t in enumerate(s[::-1]): -        if t == "A": -            ans += max(0, i - leftA) -            leftA += 1 +for i, s in enumerate(S): +    if s == "D": +        ans += cnt +    elif s == "A": +        cnt += 1 +    else: +        cnt = 0