2825. Weird sort

单点时限: 2.0 sec

内存限制: 256 MB

Having a sequence of $N$ integers $a_1, a_2, \ldots, a_N$, you need to order them in a way when no two consecutive integers have consecutive values. In other words, for all $i$, where $0<i<N$, condition $a_i+1 \neq a_{i+1}$ should be satisfied for the final sequence.

If more than one sequence satisfying this condition exists, lexicographically minimal one should be found.

输入格式

The input file consists of several data sets. In the first line of each set the sequence length $N$ $(1 \leq N \leq 50000)$ is given. The second line contains $N$ integers $a_1, a_2, \ldots, a_N$, separated by single spaces. Each integer does not exceed $10^9$ in its absolute value. The value $N=0$ indicates the end of the input file.

输出格式

For each data set you need to print result sequence in separate line. Integers in the sequence must be separated by single spaces. Print No solution if requested sequence does not exist.

样例

Input
2
1 2
6
1 2 3 4 5 6
6
1 1 2 2 3 3
0
Output
2 1
1 3 2 4 6 5
1 1 3 3 2 2

4 人解决,15 人已尝试。

6 份提交通过,共有 54 份提交。

8.9 EMB 奖励。

创建: 13 年,9 月前.

修改: 6 年,9 月前.

最后提交: 2 年,3 月前.

来源: Ukrainian

题目标签