#K50467. Rearrange Array

    ID: 28871 Type: Default 1000ms 256MiB

Rearrange Array

Rearrange Array

Given an array of integers, you are required to rearrange the array by sorting it in non-decreasing order. Sorting the array minimizes the absolute differences between consecutive elements. Formally, if the sorted array is (a_1, a_2, \ldots, a_n), then for every (1 \leq i < n) the difference (a_{i+1} - a_i) is as small as possible. This is a straightforward problem that tests your ability to handle input/output and array manipulation.

inputFormat

The first line of the input contains a single integer (n) ((1 \leq n \leq 10^5)): the number of elements in the array. The second line contains (n) space-separated integers representing the elements of the array.

outputFormat

Output a single line containing the rearranged array. The numbers should be in non-decreasing order and separated by a single space.## sample

5
3 1 6 9 2
1 2 3 6 9