S = input() ans = 0 cur = 0 for i, s in enumerate(S): if s == "A": ans += i - cur cur += 1 print(ans)