#K75742. Minimum Removals to Equalize Stack Heights

    ID: 34487 Type: Default 1000ms 256MiB

Minimum Removals to Equalize Stack Heights

Minimum Removals to Equalize Stack Heights

You are given n stacks of blocks. The height of each stack is provided as an integer. To equalize the height of all stacks, you can only remove blocks (i.e. decrease a stack's height by one for each removal). Your task is to calculate the minimum number of blocks that must be removed so that all stacks have the same height.

This can be expressed by the formula:

\(\text{removals} = \sum_{i=1}^{n} (h_i - h_{min})\)

where \(h_{min}\) is the minimum height among all stacks.

inputFormat

The input is read from stdin and consists of two lines:

  1. The first line contains an integer n representing the number of stacks.
  2. The second line contains n space-separated integers, each representing the height of a stack.

outputFormat

Output a single integer to stdout which is the minimum number of blocks that must be removed so that all stacks have the same height.

## sample
1
5
0

</p>