#C7763. Equalizing Stack Heights

    ID: 51670 Type: Default 1000ms 256MiB

Equalizing Stack Heights

Equalizing Stack Heights

You are given n stacks with varying heights. Your task is to determine the minimum number of block modifications (either additions or removals) required to make all stacks equal in height.

More formally, given an array of integers \(h_1, h_2, \dots, h_n\) representing the heights of each stack, you need to compute the minimum value of \[ \sum_{i=1}^{n} |h_i - k| \] where \(k\) is an integer chosen optimally (in fact, the median of the heights minimizes the sum of absolute deviations).

Note: If there is only one stack, zero modifications are needed.

inputFormat

The first line contains a single integer n (the number of stacks). The second line contains n space-separated integers representing the heights of the stacks.

outputFormat

Output a single integer representing the minimum number of block modifications required to equalize the heights of the stacks.

## sample
1
5
0