#K85907. Minimum Operations to Equalize Elements

    ID: 36745 Type: Default 1000ms 256MiB

Minimum Operations to Equalize Elements

Minimum Operations to Equalize Elements

In this problem, you are given a list of integers. Your task is to determine the minimum number of operations required to make all elements equal. In one operation, you can increase any element by 1. It turns out that the minimum number of operations needed is exactly max(a)min(a)\max(a) - \min(a), where aa is the list of integers.

For example, consider the list [1, 3, 2, 2]. The maximum element is 3 and the minimum element is 1, so the answer is 31=23 - 1 = 2.

inputFormat

The first line contains an integer nn (1n1051 \leq n \leq 10^5) denoting the number of elements in the list. The second line contains nn space-separated integers representing the elements of the list.

outputFormat

Output a single integer which is the minimum number of operations required to make all elements equal.## sample

1
5
0

</p>