s = eval(input())

cnt = 0

ans = 0

flag = False

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

    if flag:

        flag = False

        continue

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

        ans += cnt

        flag = True

    elif s[i] == 'A':

        cnt += 1

    else:

        cnt = 0

print(ans)
s = input().replace('BC', 'D')

cnt = 0

ans = 0

for c in s:

    if c == 'A':

        cnt += 1

    elif c == 'D':

        ans += cnt

    else:

        cnt = 0

print(ans)
s = eval(input())
cnt = 0
ans = 0
flag = False
for i in range(len(s) - 1):
    if flag:
        flag = False
        continue
    if s[i : i + 2] == "BC":
        ans += cnt
        flag = True
    elif s[i] == "A":
        cnt += 1
    else:
        cnt = 0
print(ans)

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

-s = eval(input()) +s = input().replace("BC", "D") -flag = False -for i in range(len(s) - 1): -    if flag: -        flag = False -        continue -    if s[i : i + 2] == "BC": +for c in s: +    if c == "A": +        cnt += 1 +    elif c == "D": -        flag = True -    elif s[i] == "A": -        cnt += 1