S = input() cnt = 0 res = 0 for i in range(len(S)): if S[i] == 'A': res += i - cnt cnt += 1 print(res)