s = input()

s = s.replace('BC','D')

a = 0
ans = 0

for i in range(len(s)):
    if s[i] == 'A':
        a += 1
    elif s[i] == 'D':
        if a != 0:
            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' a = 0 a 0 ans = 0 ans 0 for i in range(len(s)):
    if s[i] == 'A':
        a += 1
    elif s[i] == 'D':
        if a != 0:
            ans += a
    else:
        a = 0 i range(len(s)) range len(s) len s if s[i] == 'A':
        a += 1
    elif s[i] == 'D':
        if a != 0:
            ans += a
    else:
        a = 0 s[i] == 'A' s[i] s i 'A' a += 1 a 1 elif s[i] == 'D':
        if a != 0:
            ans += a
     s[i] == 'D' s[i] s i 'D' if a != 0:
            ans += a
     a != 0 a 0 ans += a ans a a = 0 a 0 print(ans) print ans s = s.replace('BC','D') s.replace('BC','D') s ans += a a ans a += 1 1 a s = input() input() s a = 0 0 a a = 0 0 a ans = 0 0 ans
s = input()

s = s.replace('BC','D')

a = 0
ans = 0

for i in range(len(s)):
    if s[i] == 'A':
        a += 1
    elif s[i] == 'D':
        if a != 0:
            ans += a
    else:
        a = 0

print(ans)