#K84997. Rearrange Heights
Rearrange Heights
Rearrange Heights
You are given a list of integers representing the heights of people standing in a line. Your task is to rearrange the list so that every person is shorter than the person directly in front of them, i.e. the list should be in strict ascending order. Formally, given an array \(a_1, a_2, \dots, a_n\), you need to produce an array \(b_1, b_2, \dots, b_n\) such that \(b_1 < b_2 < \dots < b_n\) and \(\{b_1, b_2, \dots, b_n\}\) is the same multiset as \(\{a_1, a_2, \dots, a_n\}\). If the list is empty, output an empty line.
Input/Output: The input will be given via standard input (stdin), and the output must be printed to standard output (stdout).
inputFormat
The first line contains an integer \(n\) representing the number of people. The second line contains \(n\) space-separated integers denoting the heights.
Note: If \(n = 0\), then there will be no heights given.
outputFormat
Output a single line containing the rearranged list of heights in ascending order, separated by a single space. If the list is empty, output an empty line.
## sample4
3 2 1 4
1 2 3 4