S = input() ans = 0 b = 0 for c in S: if c == 'A': ans += b else: b += 1 print(ans)