
s = input()
i, ans, total = 0, 0, 0

while i < len(s) - 1:
    if s[i: i + 2] == "BC":
        ans += total 
        i += 2
    elif s[i] == "A":
        total += 1
        i += 1
    else:
        total = 0
        i += 1

print(ans) s = input() s input() input i, ans, total = 0, 0, 0 i 0 ans 0 total 0 while i < len(s) - 1:
    if s[i: i + 2] == "BC":
        ans += total 
        i += 2
    elif s[i] == "A":
        total += 1
        i += 1
    else:
        total = 0
        i += 1 i < len(s) - 1 i len(s) - 1 len(s) len s 1 if s[i: i + 2] == "BC":
        ans += total 
        i += 2
    elif s[i] == "A":
        total += 1
        i += 1
    else:
        total = 0
        i += 1 s[i: i + 2] == "BC" s[i: i + 2] s i: i + 2 i i + 2 i 2 "BC" ans += total ans total i += 2 i 2 elif s[i] == "A":
        total += 1
        i += 1
     s[i] == "A" s[i] s i "A" total += 1 total 1 i += 1 i 1 total = 0 total 0 i += 1 i 1 print(ans) print ans ans += total total ans total = 0 0 total i += 2 2 i total = 0, 0, 0 0 total i += 1 1 i i += 1 1 i i, ans, total = 0, 0, 0 0 i ans, total = 0, 0, 0 0 ans total += 1 1 total s = input() input() s

s = input()
i, ans, total = 0, 0, 0

while i < len(s) - 1:
    if s[i: i + 2] == "BC":
        ans += total 
        i += 2
    elif s[i] == "A":
        total += 1
        i += 1
    else:
        total = 0
        i += 1

print(ans)