charas = list(input()) num = 0 ran = range(len(charas)) def search(num): for i in ran: if i == len(charas) - 1: print(num) return if charas[i] == 'B' and charas[i+1] == 'A': for r in range(0, i+1)[::-1]: if charas[r+1] == 'A' and charas[r] == 'B': charas[r] = 'A' charas[r+1] = 'B' num += 1 else: break break search(num) search(num)