#K34462. Minimize Absolute Differences

    ID: 25315 Type: Default 1000ms 256MiB

Minimize Absolute Differences

Minimize Absolute Differences

Given an array of integers, reorder the array so that the sum of the absolute differences between consecutive elements is minimized. It can be proven that the optimal sequence is achieved by sorting the array in non-decreasing order. Implement this approach.

Note: Consider that reordering by simply sorting the array minimizes the sum of absolute differences between adjacent values.

inputFormat

The input is read from standard input (stdin) and consists of:

  1. A single integer n (1 ≤ n ≤ 105), representing the number of elements in the array.
  2. A line with n space-separated integers.

outputFormat

Output the reordered array as n space-separated integers on a single line to standard output (stdout).

## sample
5
4 2 1 3 5
1 2 3 4 5

</p>