Problem: You are given the array consisting of elements and the integer .
You want to obtain at least equal elements in the array . In one move, you can make one of the following two operations:
- Take one of the minimum elements of the array and increase its value by one (more formally, if the minimum value of is then you choose such index that and set );
- take one of the maximum elements of the array and decrease its value by one (more formally, if the maximum value of is then you choose such index that and set ).
Your task is to calculate the minimum number of moves required to obtain at least equal elements in the array.
Input Format: The first line of the input contains two integers and () — the number of elements in and the required number of equal elements.
The second line of the input contains integers (), where is the -th element of .
Output Format: Print one integer — the minimum number of moves required to obtain at least equal elements in the array.