#K76102. Minimum Moves to Equal Array Elements

    ID: 34568 Type: Default 1000ms 256MiB

Minimum Moves to Equal Array Elements

Minimum Moves to Equal Array Elements

You are given an array of integers. In one move, you can increment n-1 elements by 1, where n is the number of elements in the array.

Your task is to determine the minimum number of moves required to make all the elements of the array equal.

Hint: It can be shown that the optimal solution is to find the minimum element min in the array and then for each element ai, the number of moves contributed is ai - min. Thus, the answer is:

\[ \text{Answer} = \sum_{i=1}^{n} (a_i - \min(a)) \]

Input is given from standard input and output should be written to standard output.

inputFormat

The first line contains a single integer n (1 ≤ n ≤ 105), representing the number of elements in the array.

The second line contains n space-separated integers, representing the elements of the array. Each element will be in the range [1, 109].

outputFormat

Output a single integer, representing the minimum number of moves required to make all the elements of the array equal.

## sample
1
1
0

</p>