# No.559 swapAB列 s = input() #s_after = 'A' * s.count('A') + 'B' * s.count('B') #print(s_after) indices = [] hands = 0 for i in range(len(s)): if s[i] == 'B': indices.append(i + 1) for j in range(len(indices)): hands += len(s) - j - indices[j] print(hands)