Under construction

Still being built. Things may change

Readability

Interview

Time limit2sMemory limit256 MB

Summary
Reorder n integers so odd and even values alternate, minimize the total moves |i-j|, and output the lexicographically smallest such order.
Level

Medium6 of 10

Topics
Sorting, Greedy, Prefix sum
Solved
No attempts yet

Problem

The Martian alphabet consists of 10910^9 integers from 11 to 10910^9. Odd integers are vowels, and even integers are consonants. A word is a sequence of such integers.

Changing the order of the integers in a word does not change its meaning, but it does change its pronunciation. If each pair of adjacent integers in a word contains one vowel and one consonant, the word is called readable.

Vasya Pupkin wants to open a restaurant of Earthern cuisine on Mars. He bought nn wooden integers for its name and placed them in a row on nn pedestals, numbered from 11 to nn. The integer on pedestal ii is aia_i.

Moving an integer from pedestal ii to pedestal jj costs ∣i−j∣|i - j| Martian rubles. During reordering, two or more integers may be on the same pedestal, but in the end each pedestal must have exactly one integer.

Find a readable word formed by reordering the integers that costs as few rubles as possible. If several such words exist, output the lexicographically smallest one.

A sequence bb is lexicographically smaller than a sequence cc of the same length if there exists an index jj such that bi=cib_i = c_i for all i<ji < j, and bj<cjb_j < c_j.

Input

The first line contains an integer nn, the number of Martian letters in the word (1≤n≤1051 \leq n \leq 10^5).

The second line contains nn space-separated integers aia_i, the letters themselves (1≤ai≤1091 \leq a_i \leq 10^9).

It is guaranteed that a solution exists.

Output

Output one line with nn space-separated integers: the required readable word.

Examples1

  1. Example 1

    Input
    5
    5 3 1 4 2
    
    Expected output
    5 2 1 4 3