#K34542. Minimum Moves to Equalize Sticks

    ID: 25332 Type: Default 1000ms 256MiB

Minimum Moves to Equalize Sticks

Minimum Moves to Equalize Sticks

You are given n sticks with various lengths. In one move, you can increase or decrease the length of any stick by 1 unit. Your task is to determine the minimum number of moves required to make all sticks equal in length. The optimal approach is to equalize all sticks to the median length, as this minimizes the total number of moves needed. Formally, you need to minimize the expression \(\sum_{i=1}^{n} |s_i - m|\) where \(s_i\) represents the length of the \(i\)-th stick and \(m\) is the median of the list \(\{s_1, s_2, \dots, s_n\}\).

Compute and output the minimum number of moves required.

inputFormat

The first line of input contains an integer \(n\) representing the number of sticks. The second line contains \(n\) space-separated integers that denote the lengths of the sticks.

outputFormat

Output a single integer: the minimum number of moves required to make all sticks equal in length.

## sample
3
1 2 3
2

</p>