S = input()
S = S.replace('BC','D')
ans = a = 0
for c in S:
    if c=='A':
        a += 1
    elif c=='D':
        ans += a
    else:
        a = 0
print(ans) S = input() S input() input S = S.replace('BC','D') S S.replace('BC','D') S.replace S replace 'BC' 'D' ans = a = 0 ans 0 = a = 0 a 0 for c in S:
    if c=='A':
        a += 1
    elif c=='D':
        ans += a
    else:
        a = 0 c S if c=='A':
        a += 1
    elif c=='D':
        ans += a
    else:
        a = 0 c=='A' c 'A' a += 1 a 1 elif c=='D':
        ans += a
     c=='D' c 'D' ans += a ans a a = 0 a 0 print(ans) print ans a = 0 0 a ans = a = 0 0 ans S = S.replace('BC','D') S.replace('BC','D') S a = 0 0 a ans += a a ans a += 1 1 a S = input() input() S
S = input()
S = S.replace('BC','D')
ans = a = 0
for c in S:
    if c=='A':
        a += 1
    elif c=='D':
        ans += a
    else:
        a = 0
print(ans)