#K39887. Stable Sorting of Heights
Stable Sorting of Heights
Stable Sorting of Heights
You are given a sequence of integer heights. Your task is to sort these heights in non-decreasing order while preserving the relative order of elements with the same value. This property is known as stable sorting. In particular, if two elements are equal, their order in the input should be retained in the output.
Mathematically, if the input list is \(H = [h_1, h_2, \dots, h_n]\), you need to output a list \(H'\) such that:
\[ H'\text{ is a permutation of } H, \quad \text{and} \quad h'_1 \leq h'_2 \leq \dots \leq h'_n. \]The algorithm should use stable sorting to ensure that the relative ordering for equal elements is preserved.
inputFormat
The first line contains a single integer \(n\) representing the number of heights.
The second line contains \(n\) space-separated integers representing the heights.
outputFormat
Output the list of sorted heights in non-decreasing order as space-separated integers on a single line.
## sample6
5 3 9 2 5 5
2 3 5 5 5 9