charas = list(input()) num = 0 def search(num): for i in range(len(charas)): 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 print("charas: ", charas) else: break break search(num) search(num)