ss = input() ans = 0 cnt = 0 for s in ss: if s == "A": ans += cnt else: cnt += 1 print(ans)