Sorting a sequence into ascending order is a common real-world task. A frequently used operation in sorting algorithms is to swap two elements of the sequence.
Given a string of distinct lowercase letters, determine the minimum number of swaps needed to rearrange it into ascending (alphabetical) order. A single swap exchanges the positions of any two characters in the string. Each character appears at most once.
The input consists of several test cases, one per line. Each line contains a string S of distinct lowercase letters (1≤∣S∣≤26); no letter repeats within a line. Input is terminated by end-of-file (EOF).
For each input line, print a single line containing the minimum number of swaps required to sort that string into ascending order.