Under construction

Still being built. Things may change

High Tide, Low Tide

Time limit1sMemory limit512 MB

Summary
Given N distinct measurements taken alternately low, high, low, high..., with rising highs and falling lows, reconstruct the original order.
Level

Easy3 of 10

Topics
Sorting, Greedy, Implementation
Solved
No attempts yet

Problem

Joe Coder is camping near the Bay of Fundy, between Nova Scotia and New Brunswick. When he arrived at the bay, someone told him that the difference between high tide and low tide there is the largest in the world. Joe is a skeptic, so he decided to check it himself. He picked a reference point, learned the times of high tide and low tide from the radio, then took a boat out to his reference point and measured the depth of the water. On the last day of the trip a strong wind scattered his records.

Joe recovered every measurement, but not the order they were taken in. He does remember a few things about them.

  • The first measurement was the water level at low tide and the second was the water level at high tide. After that the measurements kept alternating between low tide and high tide.
  • Every high tide measurement is larger than every low tide measurement.
  • As time passed, the high tide levels only rose and the low tide levels only fell.

Given the measurements in scrambled order, reconstruct the order in which Joe took them.

Input

The first line contains an integer NN (1≤N≤1001 \le N \le 100).

The second line contains NN distinct positive integers separated by spaces. Each integer is at most 10610^6.

Output

Print the NN integers on one line, separated by spaces, in the order Joe took the measurements. Exactly one order satisfies the conditions.

Hint

The measurements always start at low tide. So if NN is odd, there is one more low tide value than high tide value, and the last measurement is also a low tide value.

Examples4

  1. Example 1

    Input
    8
    10 50 40 7 3 110 90 2
    
    Expected output
    10 40 7 50 3 90 2 110
    
  2. Example 2

    Input
    1
    500000
    
    Expected output
    500000
    
  3. Example 3

    Input
    2
    9 4
    
    Expected output
    4 9
    
  4. Example 4

    Input
    3
    1 2 3
    
    Expected output
    2 3 1