s=input() res=len(s) left=0 right=res-1 while left<=right: if s[left]=="A" and s[right]=="B": left+=1 right-=1 res-=2 if s[left]=="B": left+=1 if s[right]=="A": right-=1 print(res)
s=input() res=len(s) left=0 right=res-1 while left<=right: if s[left]=="A" and s[right]=="B": left+=1 right-=1 res-=2 if s[left]=="B": left+=1 if s[right]=="A": right-=1 print(res)