S = 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 = input() S input() input N = len(S) N len(S) len S ans = num_a = 0 ans 0 = num_a = 0 num_a 0 pre_is_a = True pre_is_a True i = 0 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 i < N i N s = S[i] s S[i] 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

     s == 'A' s 'A' pre_is_a = True pre_is_a True num_a += 1 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
     s == 'B' and pre_is_a s == 'B' s 'B' pre_is_a num_bc = 0 num_bc 0 flag = True flag True for j in range(i, N-1, 2):
            if S[j:j+2] == 'BC':
                num_bc += 1
            else:
                flag = False
                break
         j range(i, N-1, 2) range i N-1 N 1 2 if S[j:j+2] == 'BC':
                num_bc += 1
            else:
                flag = False
                break
         S[j:j+2] == 'BC' S[j:j+2] S j:j+2 j j+2 j 2 'BC' num_bc += 1 num_bc 1 flag = False 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
     num_bc ans += num_a * num_bc ans num_a * num_bc num_a num_bc if flag:
                i = N
            else:
                i = j - 1
         flag i = N i N i = j - 1 i j - 1 j 1 pre_a = False pre_a False num_a = 0 num_a 0 pre_a = False pre_a False num_a = 0 num_a 0 i += 1 i 1 print(ans) print ans i = 0 0 i pre_a = False False pre_a ans = num_a = 0 0 ans pre_a = False False pre_a num_a += 1 1 num_a i += 1 1 i pre_is_a = True True pre_is_a num_a = 0 0 num_a flag = False False flag num_bc += 1 1 num_bc S = input() input() S s = S[i] S[i] s ans += num_a * num_bc num_a * num_bc ans num_a = 0 0 num_a N = len(S) len(S) N flag = True True flag i = N N i num_bc = 0 0 num_bc pre_is_a = True True pre_is_a i = j - 1 j - 1 i num_a = 0 0 num_a
S = 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)