s = list(input()) count = 0 for i in range(1, len(s)): for j in range(i, 0, -1): if s[j-1] > s[j]: s[j-1], s[j] = s[j], s[j-1] count += 1 print(count)