charas = list(input()) num = 0 if len(charas) == 1: print(num) 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': charas[i] = 'A' charas[i+1] = 'B' num += 1 break search(num) search(num)