S = eval(input())

N = len(S)

ans = num_a = 0



pre_is_a = True

i = 0

while i < N:

    s = S[i]

    if s == 'A':

        pre_is_a = True

        num_a += 1

    elif s == 'B' and pre_is_a:

        num_bc = 0

        flag = True

        for j in range(i, N-1, 2):

            if S[j:j+2] == 'BC':

                num_bc += 1

            else:

                flag = False

                break

        if num_bc:

            ans += num_a * num_bc

            if flag:

                i = N

            else:

                i = j - 1

        else:

            pre_a = False

            num_a = 0

    else:

        pre_a = False

        num_a = 0



    i += 1



print(ans)
S = eval(input())

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

S = S.replace('B', 'C')

S = S.split('C')

ans = 0



def count_inv(s):

  res = num = 0

  for si in s:

    if si == 'A':

      num += 1

    else:

      res += num

  return res





for s in S:

  ans += count_inv(s)

  

print(ans)
S = eval(input())
N = len(S)
ans = num_a = 0
pre_is_a = True
i = 0
while i < N:
    s = S[i]
    if s == "A":
        pre_is_a = True
        num_a += 1
    elif s == "B" and pre_is_a:
        num_bc = 0
        flag = True
        for j in range(i, N - 1, 2):
            if S[j : j + 2] == "BC":
                num_bc += 1
            else:
                flag = False
                break
        if num_bc:
            ans += num_a * num_bc
            if flag:
                i = N
            else:
                i = j - 1
        else:
            pre_a = False
            num_a = 0
    else:
        pre_a = False
        num_a = 0
    i += 1
print(ans)

S = eval(input())
S = S.replace("BC", "D")
S = S.replace("B", "C")
S = S.split("C")
ans = 0


def count_inv(s):
    res = num = 0
    for si in s:
        if si == "A":
            num += 1
        else:
            res += num
    return res


for s in S:
    ans += count_inv(s)
print(ans)

-N = len(S) -ans = num_a = 0 -pre_is_a = True -i = 0 -while i < N: -    s = S[i] -    if s == "A": -        pre_is_a = True -        num_a += 1 -    elif s == "B" and pre_is_a: -        num_bc = 0 -        flag = True -        for j in range(i, N - 1, 2): -            if S[j : j + 2] == "BC": -                num_bc += 1 -            else: -                flag = False -                break -        if num_bc: -            ans += num_a * num_bc -            if flag: -                i = N -            else: -                i = j - 1 +S = S.replace("BC", "D") +S = S.replace("B", "C") +S = S.split("C") +ans = 0 + + +def count_inv(s): +    res = num = 0 +    for si in s: +        if si == "A": +            num += 1 -            pre_a = False -            num_a = 0 -    else: -        pre_a = False -        num_a = 0 -    i += 1 +            res += num +    return res + + +for s in S: +    ans += count_inv(s)