s = input()
compress = []
i = 0
while i < len(s):
    if s[i:i+2] == 'BC':
        compress.append('D')
        i += 2
    else:
        compress.append(s[i])
        i += 1
ans = 0
count = 0
for x in compress:
    if x == 'A':
        count += 1
    elif x == 'D':
        ans += count
    else:
        count = 0
print(ans) s = input() s input() input compress = [] compress [] i = 0 i 0 while i < len(s):
    if s[i:i+2] == 'BC':
        compress.append('D')
        i += 2
    else:
        compress.append(s[i])
        i += 1 i < len(s) i len(s) len s if s[i:i+2] == 'BC':
        compress.append('D')
        i += 2
    else:
        compress.append(s[i])
        i += 1 s[i:i+2] == 'BC' s[i:i+2] s i:i+2 i i+2 i 2 'BC' compress.append('D') compress.append compress append 'D' i += 2 i 2 compress.append(s[i]) compress.append compress append s[i] s i i += 1 i 1 ans = 0 ans 0 count = 0 count 0 for x in compress:
    if x == 'A':
        count += 1
    elif x == 'D':
        ans += count
    else:
        count = 0 x compress if x == 'A':
        count += 1
    elif x == 'D':
        ans += count
    else:
        count = 0 x == 'A' x 'A' count += 1 count 1 elif x == 'D':
        ans += count
     x == 'D' x 'D' ans += count ans count count = 0 count 0 print(ans) print ans ans += count count ans s = input() input() s count += 1 1 count i = 0 0 i i += 2 2 i count = 0 0 count i += 1 1 i ans = 0 0 ans compress = [] [] compress count = 0 0 count
s = input()
compress = []
i = 0
while i < len(s):
    if s[i:i+2] == 'BC':
        compress.append('D')
        i += 2
    else:
        compress.append(s[i])
        i += 1
ans = 0
count = 0
for x in compress:
    if x == 'A':
        count += 1
    elif x == 'D':
        ans += count
    else:
        count = 0
print(ans)