#K4706. Rearrange Array by Sorting

    ID: 28114 Type: Default 1000ms 256MiB

Rearrange Array by Sorting

Rearrange Array by Sorting

You are given an array of integers. Your task is to rearrange the array such that it is sorted in non-decreasing order. This naturally ensures that every element in the first half of the array is less than or equal to every element in the second half. The mathematical formulation for sorting in non-decreasing order can be expressed as: [ a_1 \leq a_2 \leq \cdots \leq a_n ]

Input is provided via standard input and output should be written to standard output.

inputFormat

The first line of input contains a single integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers (a_1, a_2, \ldots, a_n).

outputFormat

Output the sorted array with elements separated by a single space. The array should be in non-decreasing order.## sample

4
4 3 1 2
1 2 3 4