s = input()

t = s.replace('BC', 'X')

# parts = []
# i_prev = 0
# for i in range(1, len(t) + 1):
#     if t[i] in 'BC':
#         parts.append(t[i_prev : i])
#         i_prev = i + 1
#     else:
#         continue
# else:
#     if i_prev < N: parts.append(t[i_prev : N])
parts = t.replace('B', 'C').split('C')

ans = 0
for part in parts:
    cnt_A = 0
    for i in range(len(part)):
        if part[i] == 'A':
            cnt_A += 1
        else:
            ans += cnt_A

print(ans) s = input() s input() input t = s.replace('BC', 'X') t s.replace('BC', 'X') s.replace s replace 'BC' 'X' parts = t.replace('B', 'C').split('C') parts t.replace('B', 'C').split('C') t.replace('B', 'C').split t.replace('B', 'C') t.replace t replace 'B' 'C' split 'C' ans = 0 ans 0 for part in parts:
    cnt_A = 0
    for i in range(len(part)):
        if part[i] == 'A':
            cnt_A += 1
        else:
            ans += cnt_A part parts cnt_A = 0 cnt_A 0 for i in range(len(part)):
        if part[i] == 'A':
            cnt_A += 1
        else:
            ans += cnt_A i range(len(part)) range len(part) len part if part[i] == 'A':
            cnt_A += 1
        else:
            ans += cnt_A part[i] == 'A' part[i] part i 'A' cnt_A += 1 cnt_A 1 ans += cnt_A ans cnt_A print(ans) print ans ans += cnt_A cnt_A ans ans = 0 0 ans cnt_A += 1 1 cnt_A t = s.replace('BC', 'X') s.replace('BC', 'X') t parts = t.replace('B', 'C').split('C') t.replace('B', 'C').split('C') parts s = input() input() s cnt_A = 0 0 cnt_A
s = input()

t = s.replace('BC', 'X')

# parts = []
# i_prev = 0
# for i in range(1, len(t) + 1):
#     if t[i] in 'BC':
#         parts.append(t[i_prev : i])
#         i_prev = i + 1
#     else:
#         continue
# else:
#     if i_prev < N: parts.append(t[i_prev : N])
parts = t.replace('B', 'C').split('C')

ans = 0
for part in parts:
    cnt_A = 0
    for i in range(len(part)):
        if part[i] == 'A':
            cnt_A += 1
        else:
            ans += cnt_A

print(ans)