S = input() count = 0 b_count = 0 for i in range(len(S)): if S[i] == "A": count += b_count else: b_count += 1 print(count)