z-sort

题意翻译

## 题目描述 z学校的一位学生发现了一种叫做z排序的排序方法。如果数组a满足以下两个条件,那么称它为z排序后的: 1.对所有的偶数i,$a_i$>=$a_{i-1}$; 2.对所有的奇数i,$a_i$<=$a_{i-1}$。 例如,数组【1,2,1,2】和【1,1,1,1】是z排序过的,而数组【1,2,3,4】不是。 你能对一个数组进行z排序吗? ## 输入输出格式 ### 输入格式: 第一行包括一个整数$n$ ( 1<=$n$<=1000) ,代表数组$a$的元素个数。 第二行包括n个整数$a_i$(1<=$a_i$<=10$^9$),代表数组$a$的每个元素 ### 输出格式: 如果可以将数组a进行z排序,输出排序后的数组,每个元素之间用空格隔开,否则输出“Impossible”。

题目描述

A student of $ z $ -school found a kind of sorting called $ z $ -sort. The array $ a $ with $ n $ elements are $ z $ -sorted if two conditions hold: 1. $ a_{i}>=a_{i-1} $ for all even $ i $ , 2. $ a_{i}<=a_{i-1} $ for all odd $ i&gt;1 $ . For example the arrays \[1,2,1,2\] and \[1,1,1,1\] are $ z $ -sorted while the array \[1,2,3,4\] isn’t $ z $ -sorted. Can you make the array $ z $ -sorted?

输入输出格式

输入格式


The first line contains a single integer $ n $ ( $ 1<=n<=1000 $ ) — the number of elements in the array $ a $ . The second line contains $ n $ integers $ a_{i} $ ( $ 1<=a_{i}<=10^{9} $ ) — the elements of the array $ a $ .

输出格式


If it's possible to make the array $ a $ $ z $ -sorted print $ n $ space separated integers $ a_{i} $ — the elements after $ z $ -sort. Otherwise print the only word "Impossible".

输入输出样例

输入样例 #1

4
1 2 2 1

输出样例 #1

1 2 1 2

输入样例 #2

5
1 3 2 2 5

输出样例 #2

1 5 2 3 2