Inversions - MarisaOJ: Marisa Online Judge

Inversions

Time limit: 1000 ms
Memory limit: 256 MB
You are given a permutation $A$ of length $n$. In one operation, you can select 2 adjacent elements $A_i$ and $A_{i + 1}$ and swap them. Find the minimum number of operations required to sort the permutation in ascending order. ### Input - The first line contains an integer $n$. - The second line contains $n$ integers $A_i$. ### Output - Print the number of operations required. ### Constraints - $1 \le n \le 10^5$. ### Example Input: ``` 4 2 4 1 3 ``` Output: ``` 3 ```