Median
Time limit2sMemory limit256 MB
Given a sequence, find the lexicographically largest permutation in which the median of every prefix is non-decreasing.
Problem
An integer sequence is good if , where is the median of .
Given a sequence , find a permutation of it that is good. If more than one exists, output the lexicographically largest one.
For a sequence , the median is the -th largest element when is odd. When is even, it is the average of the -th largest and the -th largest elements.
Input
The first line contains an integer ().
The second line contains integers ().
Output
On the first line, print integers: the lexicographically largest good permutation of the input sequence.