import re

s=eval(input())

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

sss=re.split('[BC]',ss)

ans=0

for i in sss:

    acnt=0

    for g in i:

        if g=='A':

            acnt+=1

        else:

            ans+=acnt

print(ans)

s=eval(input())

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

ans=0

cnt=0

for i in s:

    if i=='A':

        cnt+=1

    elif i=='D':

        ans+=cnt

    else:

        cnt=0

print(ans)



import re

s = eval(input())
ss = s.replace("BC", "D")
sss = re.split("[BC]", ss)
ans = 0
for i in sss:
    acnt = 0
    for g in i:
        if g == "A":
            acnt += 1
        else:
            ans += acnt
print(ans)

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

-import re - -ss = s.replace("BC", "D") -sss = re.split("[BC]", ss) +s = s.replace("BC", "D") -for i in sss: -    acnt = 0 -    for g in i: -        if g == "A": -            acnt += 1 -        else: -            ans += acnt +cnt = 0 +for i in s: +    if i == "A": +        cnt += 1 +    elif i == "D": +        ans += cnt +    else: +        cnt = 0