#C3831. Minimum Operations to Equalize Elements

    ID: 47302 Type: Default 1000ms 256MiB

Minimum Operations to Equalize Elements

Minimum Operations to Equalize Elements

You are given a sequence of n integers \(b = [b_1, b_2, \dots, b_n]\). Your task is to calculate the minimum number of operations required to make all elements equal. In one operation, you can increase an element by 1.

It can be proven that the minimum number of operations is equal to the difference between the maximum and minimum element of the sequence, i.e., \[ \text{operations} = \max(b) - \min(b)\]

Example:

Input:
4
1 2 1 3

Output: 2

</p>

In this example, \(\max(b)=3\) and \(\min(b)=1\), so the answer is \(3-1=2\).

inputFormat

The first line contains an integer \(n\) which denotes the number of elements in the array. The second line contains \(n\) space-separated integers.

outputFormat

Output a single integer representing the minimum number of operations required to make all elements equal. Mathematically, the answer is \(\max(b) - \min(b)\).

## sample
4
1 2 1 3
2