#C4840. Minimum Adjacent Swap Sorting
Minimum Adjacent Swap Sorting
Minimum Adjacent Swap Sorting
Given a string s consisting of only lowercase letters, determine the minimum number of adjacent swaps required to rearrange the characters so that the string is sorted in non-decreasing order.
The problem is equivalent to counting the number of inversions in the string. An inversion is any pair of indices \( (i, j) \) with \( i s[j] \). Mathematically, the number of swaps needed is given by:
[ \text{swaps} = \sum_{i<j} \mathbf{1}(s[i] > s[j]) ]
You are required to read the input from standard input and print the result to standard output.
inputFormat
The input consists of a single line containing a string s (possibly empty) consisting only of lowercase English letters.
outputFormat
Output a single integer which is the minimum number of adjacent swaps needed to sort the string in non-decreasing order.
## sampledcba
6
</p>