s=list(input()) count=0 for i in range(len(s)): if s[i]=="B": for j in range(i,len(s)): if s[j]=="A": s[j-1],s[j]=s[j],s[j-1] count+=1 print(count)