You hold n cards with distinct integer values. You want to arrange them into a single face-down deck (a top-to-bottom order) so that the following reveal process outputs the values in strictly increasing order.
Reveal process (the deck behaves as a queue; the top is the front):
- Take the top card and reveal (output) it.
- If any cards remain, take the new top card and move it to the bottom of the deck.
- Repeat until no cards remain.
Exactly one top-to-bottom arrangement makes the revealed sequence increasing. Output that arrangement.
Input format
Line 1: an integer n.
Line 2: n space-separated distinct integers, the card values in any order.
Output format
One line with n space-separated integers: the deck from top to bottom that reveals in increasing order.
Constraints
- 1 <= n <= 8
- Card values are distinct, and each has absolute value <= 1000000000.