#K46262. Minimum Steps to Equalize Scores

    ID: 27938 Type: Default 1000ms 256MiB

Minimum Steps to Equalize Scores

Minimum Steps to Equalize Scores

You are given a list of scores. In one step, you can increment or decrement any element by 1. Your task is to determine the minimum number of steps required to make all the scores equal.

It can be shown that the optimal strategy is to convert all scores to the median value. In other words, if the sorted list is \(s_0, s_1, \dots, s_{n-1}\), then the answer is given by \[ \sum_{i=0}^{n-1} |s_i - s_{\lfloor n/2 \rfloor}|, \] where \(n\) is the number of scores.

If the list is empty, output 0.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains an integer \(N\) which denotes the number of scores. \(N\) can be zero.
  • If \(N > 0\), the second line contains \(N\) space-separated integers representing the scores.

outputFormat

Print to stdout a single integer: the minimum number of steps required to make all scores equal.

## sample
3
1 2 3
2

</p>