#K6261. Minimum Operations to Make All Elements Equal

    ID: 31570 Type: Default 1000ms 256MiB

Minimum Operations to Make All Elements Equal

Minimum Operations to Make All Elements Equal

You are given a sequence of n integers. In one operation, you can choose any subsequence of the sequence and increase each chosen element by 1. Your task is to determine the minimum number of operations required to make all elements of the sequence equal.

It can be shown that the answer is equal to \(\max(sequence) - \min(sequence)\). This is because in each operation, you can increase all elements that are less than the maximum value. Keep applying the operation until all elements become equal.

Example:

Input: 4\n2 4 4 6
Output: 4

inputFormat

The first line contains a single integer n (\(1 \le n \le 10^5\)), representing the number of elements in the sequence. The second line contains \(n\) integers separated by spaces, representing the elements of the sequence.

outputFormat

Output a single integer: the minimum number of operations required to make all elements equal.

## sample
4
2 4 4 6
4