S = eval(input())



ans = 0

cnt = 0

flg = 0



for i in range(len(S)-1) :

    if S[i] == "A" :

        cnt += 1

    elif S[i]+S[i+1] == "BC" :

        ans += cnt

        flg = 1

    elif flg :

        flg = 0

    else :

        cnt = 0



print(ans)

S = input().replace("BC","D")



ans = 0

cnt = 0



for s in S :

    if s == "A" :

        cnt += 1

    elif s == "D" :

        ans += cnt

    else :

        cnt = 0



print(ans)

S = eval(input())
ans = 0
cnt = 0
flg = 0
for i in range(len(S) - 1):
    if S[i] == "A":
        cnt += 1
    elif S[i] + S[i + 1] == "BC":
        ans += cnt
        flg = 1
    elif flg:
        flg = 0
    else:
        cnt = 0
print(ans)

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

-S = eval(input()) +S = input().replace("BC", "D") -flg = 0 -for i in range(len(S) - 1): -    if S[i] == "A": +for s in S: +    if s == "A": -    elif S[i] + S[i + 1] == "BC": +    elif s == "D": -        flg = 1 -    elif flg: -        flg = 0