P1716 Max-Min Alternating Sequence

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 $n$ ($n \le 1000$) integers (all within the `long int` range, i.e., $-2147483648 \sim 2147483647$). The first number of the sequence is the maximum among the $n$ 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 $n$ integers.

Input Format

The first line contains an integer $n$. The next $n$ lines contain the $n$ integers described above, one integer per line.

Output Format

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

Explanation/Hint

For $100\%$ of the testdata, $1 \le n \le 1000$. Translated by ChatGPT 5