Input: N = 5, D = 2, A[] = {2, 8, 10, 4, 6}
Output: 6
Explanation:
1st Operation: Choose A[3] and A[1], because abs(3-1) = 2, then decrement A[3] and increment A[1]. After that A[] = {3, 8, 9, 4, 6}.
2nd Operation: Choose A[3] and A[1] again then decrement A[3] and increment A[1]. After that A[] = {4, 8, 8, 4, 6}.
3rd Operation: Choose A[3] and A[1], decrement A[3] and increment A[1]. After that A[] = {5, 8, 7, 4, 6}.
4th Operation: Choose A[3] and A[1], decrement A[3] and increment A[1]. After that A[] = {6, 8, 6, 4, 6}.
5th Operation: Choose A[2] and A[4] as abs(2-4) = 2, decrement A[2] and increment A[4]. After that A[] = {6, 7, 6, 5, 6}.
6th Operation: Choose A[2] and A[4] again, decrement A[2] and increment A[4]. After that A[] = {6, 6, 6, 6, 6}.
Now it can be verified that all the elements are equal. 6 are the minimum operations required to do so.
Input: N = 6, D = 1, A[] = {3, 4, 5, 1, 4, 5}
Output: -1
Explanation: It can be verified that all elements can't made equal by using the given operation.