s=list(input()) cnt=0 while True: try: s=s[s.index('B'):] an=s.index('A') bn=s.index('B') s[an]='B' s[an-1]='A' cnt+=1 except: break print(cnt)