st = list(input()) count = 0 while True: if (len(st) == 1) or (sorted(st) == st): break for i in range(len(st)-1): if st[i] == "B" and st[i+1] == "A": st[i] = "A" st[i+1] = "B" count += 1 print(count)