s = input()
s = s.replace('BC','x')

a_flag = False
ans = 0
last_a = 0
for si in s:
    if si == 'A':
        a_flag = True
        last_a += 1
    elif si == 'x' and a_flag:
        ans += last_a
    else:
        a_flag = False
        last_a = 0

print(ans) s = input() s input() input s = s.replace('BC','x') s s.replace('BC','x') s.replace s replace 'BC' 'x' a_flag = False a_flag False ans = 0 ans 0 last_a = 0 last_a 0 for si in s:
    if si == 'A':
        a_flag = True
        last_a += 1
    elif si == 'x' and a_flag:
        ans += last_a
    else:
        a_flag = False
        last_a = 0 si s if si == 'A':
        a_flag = True
        last_a += 1
    elif si == 'x' and a_flag:
        ans += last_a
    else:
        a_flag = False
        last_a = 0 si == 'A' si 'A' a_flag = True a_flag True last_a += 1 last_a 1 elif si == 'x' and a_flag:
        ans += last_a
     si == 'x' and a_flag si == 'x' si 'x' a_flag ans += last_a ans last_a a_flag = False a_flag False last_a = 0 last_a 0 print(ans) print ans s = input() input() s last_a = 0 0 last_a last_a += 1 1 last_a s = s.replace('BC','x') s.replace('BC','x') s a_flag = False False a_flag a_flag = False False a_flag ans += last_a last_a ans ans = 0 0 ans last_a = 0 0 last_a a_flag = True True a_flag
s = input()
s = s.replace('BC','x')

a_flag = False
ans = 0
last_a = 0
for si in s:
    if si == 'A':
        a_flag = True
        last_a += 1
    elif si == 'x' and a_flag:
        ans += last_a
    else:
        a_flag = False
        last_a = 0

print(ans)
