import sys input=lambda: sys.stdin.readline().rstrip() S=input() ans=0 ct=0 for s in S: if s=="A": ans+=ct else: ct+=1 print(ans)