s = input()
d = []
i = 0
while i < len(s)-1:
    if s[i] == 'B' and s[i+1] == 'C':
        d.append('D')
        i += 2
    else:
        d.append(s[i])
        i += 1
ans = 0
x = 0
for i in range(len(d)):
    if d[i] == 'A':
        x += 1
    elif d[i] == 'D':
        ans += x
    else:
        x = 0
print(ans) s = input() s input() input d = [] d [] i = 0 i 0 while i < len(s)-1:
    if s[i] == 'B' and s[i+1] == 'C':
        d.append('D')
        i += 2
    else:
        d.append(s[i])
        i += 1 i < len(s)-1 i len(s)-1 len(s) len s 1 if s[i] == 'B' and s[i+1] == 'C':
        d.append('D')
        i += 2
    else:
        d.append(s[i])
        i += 1 s[i] == 'B' and s[i+1] == 'C' s[i] == 'B' s[i] s i 'B' s[i+1] == 'C' s[i+1] s i+1 i 1 'C' d.append('D') d.append d append 'D' i += 2 i 2 d.append(s[i]) d.append d append s[i] s i i += 1 i 1 ans = 0 ans 0 x = 0 x 0 for i in range(len(d)):
    if d[i] == 'A':
        x += 1
    elif d[i] == 'D':
        ans += x
    else:
        x = 0 i range(len(d)) range len(d) len d if d[i] == 'A':
        x += 1
    elif d[i] == 'D':
        ans += x
    else:
        x = 0 d[i] == 'A' d[i] d i 'A' x += 1 x 1 elif d[i] == 'D':
        ans += x
     d[i] == 'D' d[i] d i 'D' ans += x ans x x = 0 x 0 print(ans) print ans i += 1 1 i ans += x x ans x += 1 1 x i = 0 0 i i += 2 2 i s = input() input() s ans = 0 0 ans x = 0 0 x d = [] [] d x = 0 0 x
s = input()
d = []
i = 0
while i < len(s)-1:
    if s[i] == 'B' and s[i+1] == 'C':
        d.append('D')
        i += 2
    else:
        d.append(s[i])
        i += 1
ans = 0
x = 0
for i in range(len(d)):
    if d[i] == 'A':
        x += 1
    elif d[i] == 'D':
        ans += x
    else:
        x = 0
print(ans)