r = 0; s = 0 for i in input(): b = i == 'A' r += [0, s][b] s += [1, 0][b] print(r)