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