s = eval(input())

total = 0

i = 0

inRange = False

range_start = 0

range_minus = 0

range_cnt = 0

 

while i < len(s)-1:

    # BC=>0

    if s[i] == 'B' and s[i+1] == 'C':

        if inRange:

            total += (range_cnt - range_minus)

            range_cnt += 1

            range_minus += 1

        i += 1

    elif s[i] == 'A':

        inRange = True

        range_cnt += 1

    else:

        inRange = False

        range_start = 0

        range_minus = 0

        range_cnt = 0

    i+=1

    

print(total)
s = eval(input())

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

total = 0

cnt = 0

for it in s:

    if it == 'A':

        cnt+=1

    elif it=='D':

        total += cnt

    else:

        cnt = 0

print(total)
s = eval(input())
total = 0
i = 0
inRange = False
range_start = 0
range_minus = 0
range_cnt = 0
while i < len(s) - 1:
    # BC=>0
    if s[i] == "B" and s[i + 1] == "C":
        if inRange:
            total += range_cnt - range_minus
            range_cnt += 1
            range_minus += 1
        i += 1
    elif s[i] == "A":
        inRange = True
        range_cnt += 1
    else:
        inRange = False
        range_start = 0
        range_minus = 0
        range_cnt = 0
    i += 1
print(total)

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

+s = s.replace("BC", "D") -i = 0 -inRange = False -range_start = 0 -range_minus = 0 -range_cnt = 0 -while i < len(s) - 1: -    # BC=>0 -    if s[i] == "B" and s[i + 1] == "C": -        if inRange: -            total += range_cnt - range_minus -            range_cnt += 1 -            range_minus += 1 -        i += 1 -    elif s[i] == "A": -        inRange = True -        range_cnt += 1 +cnt = 0 +for it in s: +    if it == "A": +        cnt += 1 +    elif it == "D": +        total += cnt -        inRange = False -        range_start = 0 -        range_minus = 0 -        range_cnt = 0 -    i += 1 +        cnt = 0