S = list(input()) ans = 0 while True: for i in range(len(S)-1): if S[i:i+2] == ['B', 'A']: S[i], S[i+1] = S[i+1], S[i] ans += 1 if sorted(S) == S: break print(ans)