#P1730F. Almost Sorted
Almost Sorted
Description
You are given a permutation of length and a positive integer . Consider a permutation of length such that for any integers and , where , we have
Find the minimum possible number of inversions in a permutation .
A permutation is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array) and is also not a permutation ( but there is in the array).
An inversion in a permutation is a pair of indices and () such that , but .
The first line contains two integers and (, ).
The second line contains distinct integers ().
Print the minimum possible number of inversions in the permutation .
Input
The first line contains two integers and (, ).
The second line contains distinct integers ().
Output
Print the minimum possible number of inversions in the permutation .
Note
In the first example, the only permutation is ( inversions). Then .
In the second example, the only permutation with inversion is . Then , , .
In the third example, one of the possible permutations with inversions is . Then , , , , .