Operations on an Array
87% Success5311 Attempts20 Points1s Time Limit256MB Memory1024 KB Max Code
You are given an array \(A\) containing \(N\) elements. You need to make the elements of the array equal. You are allowed to do the following operations:
- Decrease an element by \(1\). If the element becomes \(0\), it is removed from the array.
- Increase an element by \(1\).
You need to find the minimum number of operations required to do so.
Input Format
- The First line of input contains an integer \(N\), denoting the number of elements in \(A\).
- Second line contains \(N\) space seperated integers, the elements of the array \(A\).
Output Format
- Print a single integer representing the number of operations as asked above.
Constraints
- \(1 \le N \le 10^3\)
- \(1 \le A[i] \le 10^9\)
Examples
Input
3 2 2 3
Output
1
Explanation
We can decrease the \(3^{rd}\) element by \(1\) and all elements become same. Hence, answer is \(1\).
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Loading Editor...
Results