S=input() B=0 ANS=0 for s in S: if s=="A": ANS+=B else: B+=1 print(ANS)