S = input() ans = 0 if len(set(S)) != 1: s = list(S) for i in range(len(s)): if s[i] == "A": j = i while s[i-1]=="B": i-=1 ans+=1 temp=s[i] s[i]=s[j] s[j]=temp print(ans)