s = eval(input())



ans = 0

x = 0

index = 0



while index < len(s):

    if s[index] == 'A':

        x += 1

        index += 1

    elif s[index:index+2] == "BC":

        ans += x

        index += 2

    else:

         index += 1

         x = 0



print(ans)

s = eval(input())

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



ans = 0

x = 0

for i in range(len(s)):

    if s[i] == 'A':

        x += 1

    elif s[i] == 'D':

        ans += x

    else:

        x = 0



print(ans)

s = eval(input())
ans = 0
x = 0
index = 0
while index < len(s):
    if s[index] == "A":
        x += 1
        index += 1
    elif s[index : index + 2] == "BC":
        ans += x
        index += 2
    else:
        index += 1
        x = 0
print(ans)

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

+s = s.replace("BC", "D") -index = 0 -while index < len(s): -    if s[index] == "A": +for i in range(len(s)): +    if s[i] == "A": -        index += 1 -    elif s[index : index + 2] == "BC": +    elif s[i] == "D": -        index += 2 -        index += 1