#K52422. Minimum Blocks Removal

    ID: 29306 Type: Default 1000ms 256MiB

Minimum Blocks Removal

Minimum Blocks Removal

You are given n piles of blocks, where the i-th pile has a height hi (a non-negative integer). You can only remove blocks from the piles. Your task is to remove the minimum number of blocks so that all piles have the same height. The optimal strategy is to reduce every pile to the height of the smallest pile.

This can be mathematically formulated as:

$$\text{blocks to remove} = \sum_{i=1}^{n}h_i - n\times\min(h_1, h_2, \ldots, h_n)$$

Make sure your program reads from standard input and writes to standard output.

inputFormat

The input consists of two lines. The first line contains a single integer n (where n ≥ 1) representing the number of piles. The second line contains n non-negative integers separated by spaces, where each integer denotes the height of a pile.

outputFormat

Output a single integer: the minimum number of blocks that need to be removed so that all piles have equal height.## sample

4
3 7 2 5
9