Baltic Olympiad in Informatics: 2016 Day 2, Problem 3
You are given a sequence of numbers . Each number appears exactly once in the sequence.
You can modify the sequence using swaps. There are consecutive turns numbered . On turn you can either swap values and in the sequence or do nothing.
Sequence is lexicographically smaller than sequence if there exists an index such that for all and .
What is the lexicographically minimal sequence you can obtain?
Constraints
Subtask 1 [10%]
Subtask 2 [11%]
Subtask 3 [27%]
Subtask 4 [20%]
Subtask 5 [32%]
Input Specification
The first input line contains an integer .
The second input line contains integers: the numbers in the sequence.
Output Specification
You should output integers: the lexicographically minimal sequence.
Sample Input 1
5
3 4 2 5 1
Sample Output 1
2 1 3 4 5
Comments