s=input() ans=0 l=0 for i in range(len(s)): if s[i]=='A': ans+=i-l l+=1 print(ans)