s = eval(input())

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

ans = 0

a = 0

for k in range(len(s)):

    if s[k] == "A":

        a += 1

    elif s[k] == "D":

        ans += a

    else:

        a = 0

print(ans)

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

ans = 0

c = 0

for e in s:

    if e == "A":

        c += 1

    elif e == "D":

        ans += c

    else:

        c = 0

print(ans)

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

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

-s = eval(input()) -s = s.replace("BC", "D") +s = input().replace("BC", "D") -a = 0 -for k in range(len(s)): -    if s[k] == "A": -        a += 1 -    elif s[k] == "D": -        ans += a +c = 0 +for e in s: +    if e == "A": +        c += 1 +    elif e == "D": +        ans += c -        a = 0 +        c = 0