Given an array of n integers, find the minimum number of adjacent swaps
needed to sort it in non-decreasing order. (This is a classic fact: that
minimum equals the number of inversions — pairs i < j with a[i] > a[j].)
Line 1: integer n (1 ≤ n ≤ 2·10^5)
Line 2: n integers a_1 … a_n (-10^9 ≤ a_i ≤ 10^9)
A single integer: the minimum number of adjacent swaps to sort the array.
Input:
5
5 4 3 2 1
Output:
10
Case 1
5 5 4 3 2 1
10
Case 2
5 1 2 3 4 5
0
Input
5 5 4 3 2 1
Expected Output
10
Run or submit your code to see output here.