logo AlgoBeat OnlineJudge
登录 注册

#217039. [NWERC 2020] Hot Springs

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Iceland is famous for its geothermal activity, which supplies the country with much of its electricity and heating. It is also a source of pleasure, in the form of hot springs.

Kalle is visiting one of Iceland's famous hot springs. It contains pools of water, where the th one has temperature . Although staying in one of the warmer pools for a long time sure is relaxing, Kalle is on a very tight schedule and just wants a quick dip in each of the pools. As you may know, the nicest thing about hot baths is the contrast between hot and cold. Therefore, to get the most out of his stay, Kalle wants to find an ordering of the pools so that the difference in temperature between subsequent pools is increasing.

Given a sequence of pool temperatures , rearrange them into a new sequence such that for all it holds that

输入格式

The input consists of:

  • One line with an integer (), the number of pools.

  • One line with integers ( for each ), the temperatures in each of the pools.

输出格式

Output a rearrangement of the sequence satisfying the given requirement. If no solution exists, output "impossible". If there are multiple valid solutions, you may output any one of them.

样例

样例输入 1

3
1 3 4

样例输出 1

4 3 1 

样例输入 2

6
0 0 1 -1 -6 3

样例输出 2

0 1 3 -1 -6 0