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