#K976. Minimize Absolute Difference Sum

    ID: 39101 Type: Default 1000ms 256MiB

Minimize Absolute Difference Sum

Minimize Absolute Difference Sum

You are given ( n ) magical stones, each with an associated power value. Your task is to rearrange the stones so that the sum of the absolute differences between consecutive stones is minimized. In other words, if the stones are arranged as ( a_1, a_2, \dots, a_n ), you are to minimize the quantity: [ \sum_{i=1}^{n-1} |a_{i+1} - a_i| ] It can be shown that the optimal arrangement for any list of integers is to sort them in non-decreasing order.

inputFormat

The input consists of two lines. The first line contains a single integer ( n ) (( 1 \leq n \leq 10^5 )), which represents the number of magical stones. The second line contains ( n ) space-separated integers, where each integer represents the power value of a stone.

outputFormat

Output a single line with ( n ) integers sorted in non-decreasing order. This order minimizes the sum of absolute differences between consecutive stone powers.## sample

4
4 1 3 2
1 2 3 4

</p>