#P1716. 双调序列

双调序列

Description

Students in the computer group often play small brain-teaser PK games. One day, a student invented a new sequence: the "Max-Min alternating sequence," defined as follows:

Suppose there are nn (n1000n \le 1000) integers (all within the long int range, i.e., 21474836482147483647-2147483648 \sim 2147483647). The first number of the sequence is the maximum among the nn integers, the second number is the minimum, the third number is the second largest, the fourth number is the second smallest, and so on. Numbers that have been taken cannot be chosen again, proceeding until all numbers are used.

Please write a program to produce this sequence for the given nn integers.

Input Format

The first line contains an integer nn.

The next nn lines contain the nn integers described above, one integer per line.

Output Format

Output nn lines, each containing one integer, forming the required Max-Min alternating sequence.

5
10
-1
3
3
-9

10
-9
3
-1
3

Hint

For 100%100\% of the testdata, 1n10001 \le n \le 1000.

Translated by ChatGPT 5