Sawtooth Sequence

No attempts yetTime limit1sMemory limit1024 MB

Statement

You are given NN distinct natural numbers. Using every number exactly once, arrange them into a sawtooth (zigzag) sequence.

A sequence is sawtooth-shaped when the order relation of each pair of adjacent elements alternates. That is, it must satisfy one of the two forms below:

  • a1<a2>a3<a4>a5<a6>a7a_1 < a_2 > a_3 < a_4 > a_5 < a_6 > a_7 \cdots (odd positions are valleys, even positions are peaks), or
  • a1>a2<a3>a4<a5>a6<a7a_1 > a_2 < a_3 > a_4 < a_5 > a_6 < a_7 \cdots (odd positions are peaks, even positions are valleys).

Several sawtooth sequences may be possible from the given numbers. Output the lexicographically smallest one. When comparing two sequences lexicographically, the sequence with the smaller value at the first position where they differ is the smaller one.

Input

The first line contains the count of numbers NN. The second line contains the NN distinct natural numbers aia_i, separated by spaces.

Output

On the first line, print the lexicographically smallest sawtooth sequence that uses all of the given numbers, separated by spaces. (Both forms above are considered as candidates.)

Constraints

  • 1N10001 \le N \le 1000
  • 1ai100001 \le a_i \le 10000
  • All aia_i are distinct.