s = input()
n = len(s)
s = list(s.replace('BC','D'))
a_count = 0
ans = 0
i = 0
while i < len(s) - 1 :
    if s[i:i+2] == ['A','D']:
        ans += a_count + 1
        s[i+1] = 'A'
        s[i] = 'D'
    else:
        if s[i] == 'A':
            a_count += 1
        else:
            a_count = 0
    i += 1
print(ans) s = input() s input() input n = len(s) n len(s) len s s = list(s.replace('BC','D')) s list(s.replace('BC','D')) list s.replace('BC','D') s.replace s replace 'BC' 'D' a_count = 0 a_count 0 ans = 0 ans 0 i = 0 i 0 while i < len(s) - 1 :
    if s[i:i+2] == ['A','D']:
        ans += a_count + 1
        s[i+1] = 'A'
        s[i] = 'D'
    else:
        if s[i] == 'A':
            a_count += 1
        else:
            a_count = 0
    i += 1 i < len(s) - 1 i len(s) - 1 len(s) len s 1 if s[i:i+2] == ['A','D']:
        ans += a_count + 1
        s[i+1] = 'A'
        s[i] = 'D'
    else:
        if s[i] == 'A':
            a_count += 1
        else:
            a_count = 0
     s[i:i+2] == ['A','D'] s[i:i+2] s i:i+2 i i+2 i 2 ['A','D'] 'A' 'D' ans += a_count + 1 ans a_count + 1 a_count 1 s[i+1] = 'A' s[i+1] s i+1 i 1 'A' s[i] = 'D' s[i] s i 'D' if s[i] == 'A':
            a_count += 1
        else:
            a_count = 0
     s[i] == 'A' s[i] s i 'A' a_count += 1 a_count 1 a_count = 0 a_count 0 i += 1 i 1 print(ans) print ans s = list(s.replace('BC','D')) list(s.replace('BC','D')) s a_count = 0 0 a_count i += 1 1 i a_count += 1 1 a_count n = len(s) len(s) n ans += a_count + 1 a_count + 1 ans ans = 0 0 ans i = 0 0 i s = input() input() s a_count = 0 0 a_count
s = input()
n = len(s)
s = list(s.replace('BC','D'))
a_count = 0
ans = 0
i = 0
while i < len(s) - 1 :
    if s[i:i+2] == ['A','D']:
        ans += a_count + 1
        s[i+1] = 'A'
        s[i] = 'D'
    else:
        if s[i] == 'A':
            a_count += 1
        else:
            a_count = 0
    i += 1
print(ans)