S = input()

A = []

ok = 1
ans = 0
cnt = 0
for i in range(len(S)):
    if ok == 1 and i < len(S)-1 and S[i] == 'B' and S[i+1] == 'C':
        A.append('B')
        ans += cnt
    elif S[i] == 'A':
        A.append('A')
        cnt += 1
        ok = 1
    elif ok == 1 and i > 0 and S[i-1] == 'B' and S[i] == 'C':
        continue
    else:
        A = []
        cnt = 0
        ok = 0

print(ans) S = input() S input() input A = [] A [] ok = 1 ok 1 ans = 0 ans 0 cnt = 0 cnt 0 for i in range(len(S)):
    if ok == 1 and i < len(S)-1 and S[i] == 'B' and S[i+1] == 'C':
        A.append('B')
        ans += cnt
    elif S[i] == 'A':
        A.append('A')
        cnt += 1
        ok = 1
    elif ok == 1 and i > 0 and S[i-1] == 'B' and S[i] == 'C':
        continue
    else:
        A = []
        cnt = 0
        ok = 0 i range(len(S)) range len(S) len S if ok == 1 and i < len(S)-1 and S[i] == 'B' and S[i+1] == 'C':
        A.append('B')
        ans += cnt
    elif S[i] == 'A':
        A.append('A')
        cnt += 1
        ok = 1
    elif ok == 1 and i > 0 and S[i-1] == 'B' and S[i] == 'C':
        continue
    else:
        A = []
        cnt = 0
        ok = 0 ok == 1 and i < len(S)-1 and S[i] == 'B' and S[i+1] == 'C' ok == 1 and i < len(S)-1 and S[i] == 'B' ok == 1 and i < len(S)-1 ok == 1 ok 1 i < len(S)-1 i len(S)-1 len(S) len S 1 S[i] == 'B' S[i] S i 'B' S[i+1] == 'C' S[i+1] S i+1 i 1 'C' A.append('B') A.append A append 'B' ans += cnt ans cnt elif S[i] == 'A':
        A.append('A')
        cnt += 1
        ok = 1
     S[i] == 'A' S[i] S i 'A' A.append('A') A.append A append 'A' cnt += 1 cnt 1 ok = 1 ok 1 elif ok == 1 and i > 0 and S[i-1] == 'B' and S[i] == 'C':
        continue
     ok == 1 and i > 0 and S[i-1] == 'B' and S[i] == 'C' ok == 1 and i > 0 and S[i-1] == 'B' ok == 1 and i > 0 ok == 1 ok 1 i > 0 i 0 S[i-1] == 'B' S[i-1] S i-1 i 1 'B' S[i] == 'C' S[i] S i 'C' continue A = [] A [] cnt = 0 cnt 0 ok = 0 ok 0 print(ans) print ans cnt += 1 1 cnt cnt = 0 0 cnt ans += cnt cnt ans A = [] [] A ok = 0 0 ok S = input() input() S ok = 1 1 ok cnt = 0 0 cnt A = [] [] A ans = 0 0 ans ok = 1 1 ok
S = input()

A = []

ok = 1
ans = 0
cnt = 0
for i in range(len(S)):
    if ok == 1 and i < len(S)-1 and S[i] == 'B' and S[i+1] == 'C':
        A.append('B')
        ans += cnt
    elif S[i] == 'A':
        A.append('A')
        cnt += 1
        ok = 1
    elif ok == 1 and i > 0 and S[i-1] == 'B' and S[i] == 'C':
        continue
    else:
        A = []
        cnt = 0
        ok = 0

print(ans)