s = input()
#Aの海をかき分けてBCが進む

r = list(reversed(list(s)))
r = ['X'] + r + ['X']
#print(r)
BC_cnt = 0
A_cnt = 0
cnt = 0
for i in range(1, len(s) + 1):
    if r[i] == 'A':
        cnt += BC_cnt
        #print(BC_cnt, A_cnt)
    elif r[i] == 'C' and r[i + 1] == 'B':
        BC_cnt += 1
    elif r[i - 1] == 'C' and r[i] == 'B':
        pass
    else:
        BC_cnt = 0
print(cnt) s = input() s input() input r = list(reversed(list(s))) r list(reversed(list(s))) list reversed(list(s)) reversed list(s) list s r = ['X'] + r + ['X'] r ['X'] + r + ['X'] ['X'] + r ['X'] 'X' r ['X'] 'X' BC_cnt = 0 BC_cnt 0 A_cnt = 0 A_cnt 0 cnt = 0 cnt 0 for i in range(1, len(s) + 1):
    if r[i] == 'A':
        cnt += BC_cnt
        #print(BC_cnt, A_cnt)
    elif r[i] == 'C' and r[i + 1] == 'B':
        BC_cnt += 1
    elif r[i - 1] == 'C' and r[i] == 'B':
        pass
    else:
        BC_cnt = 0 i range(1, len(s) + 1) range 1 len(s) + 1 len(s) len s 1 if r[i] == 'A':
        cnt += BC_cnt
        #print(BC_cnt, A_cnt)
    elif r[i] == 'C' and r[i + 1] == 'B':
        BC_cnt += 1
    elif r[i - 1] == 'C' and r[i] == 'B':
        pass
    else:
        BC_cnt = 0 r[i] == 'A' r[i] r i 'A' cnt += BC_cnt cnt BC_cnt elif r[i] == 'C' and r[i + 1] == 'B':
        BC_cnt += 1
     r[i] == 'C' and r[i + 1] == 'B' r[i] == 'C' r[i] r i 'C' r[i + 1] == 'B' r[i + 1] r i + 1 i 1 'B' BC_cnt += 1 BC_cnt 1 elif r[i - 1] == 'C' and r[i] == 'B':
        pass
     r[i - 1] == 'C' and r[i] == 'B' r[i - 1] == 'C' r[i - 1] r i - 1 i 1 'C' r[i] == 'B' r[i] r i 'B' BC_cnt = 0 BC_cnt 0 print(cnt) print cnt cnt = 0 0 cnt cnt += BC_cnt BC_cnt cnt BC_cnt = 0 0 BC_cnt BC_cnt += 1 1 BC_cnt A_cnt = 0 0 A_cnt s = input() input() s BC_cnt = 0 0 BC_cnt r = ['X'] + r + ['X'] ['X'] + r + ['X'] r r = list(reversed(list(s))) list(reversed(list(s))) r
s = input()
#Aの海をかき分けてBCが進む

r = list(reversed(list(s)))
r = ['X'] + r + ['X']
#print(r)
BC_cnt = 0
A_cnt = 0
cnt = 0
for i in range(1, len(s) + 1):
    if r[i] == 'A':
        cnt += BC_cnt
        #print(BC_cnt, A_cnt)
    elif r[i] == 'C' and r[i + 1] == 'B':
        BC_cnt += 1
    elif r[i - 1] == 'C' and r[i] == 'B':
        pass
    else:
        BC_cnt = 0
print(cnt)
