S = list(input().strip()) cnt = 0 while True: for i in range(len(S) - 1): if S[i] == 'B' and S[i+1] == 'A': S[i], S[i+1] = S[i+1], S[i] cnt += 1 break else: break print(cnt)