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