s = eval(input())



ans, cnta = 0, 0

for i in range(len(s)):

    if s[i] == 'A':

        cnta += 1

    elif s[i:i + 2] == 'BC':

        ans += cnta

    elif s[i - 1:i + 1] != 'BC':

        cnta = 0

print(ans)

s = input().replace('BC','a')



ans, cnta = 0, 0

for i in range(len(s)):

    if s[i] == 'A':

        cnta += 1

    elif s[i] == 'a':

        ans += cnta

    else:

        cnta = 0

print(ans)

s = eval(input())
ans, cnta = 0, 0
for i in range(len(s)):
    if s[i] == "A":
        cnta += 1
    elif s[i : i + 2] == "BC":
        ans += cnta
    elif s[i - 1 : i + 1] != "BC":
        cnta = 0
print(ans)

s = input().replace("BC", "a")
ans, cnta = 0, 0
for i in range(len(s)):
    if s[i] == "A":
        cnta += 1
    elif s[i] == "a":
        ans += cnta
    else:
        cnta = 0
print(ans)

-s = eval(input()) +s = input().replace("BC", "a") -    elif s[i : i + 2] == "BC": +    elif s[i] == "a": -    elif s[i - 1 : i + 1] != "BC": +    else: