l=list(input()) n=len(l) ans=0 le=0 for i in range(n): if l[i]=="A": ans+=i-le le+=1 print(ans)