Minimum Swaps

No attempts yetTime limit1sMemory limit128 MB

Problem

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.

Input

The input consists of several test cases, one per line. Each line contains a string SS of distinct lowercase letters (1S261 \le |S| \le 26); no letter repeats within a line. Input is terminated by end-of-file (EOF).

Output

For each input line, print a single line containing the minimum number of swaps required to sort that string into ascending order.