Cossack Vus and Lexicography
Kozak recently received an array consisting of integers.
Vus wants to rearrange the elements of this array so that no two adjacent numbers are the same. Among all possible arrangements, he is interested in finding the lexicographically smallest one.
To clarify, lexicographical order is determined as follows: Given two arrays, identify the first position where they differ. If the element in the first array is smaller at this position, then the first array is considered lexicographically smaller. Conversely, if the element in the second array is smaller, then the first array is larger. For example, the following inequalities hold: < , , and .
Input
The first line contains an integer , representing the number of elements in the array.
The second line contains integers , which are the elements of the array.
Output
If it is impossible to rearrange Vus's array to meet the conditions, output a single number .
Otherwise, output integers representing the lexicographically smallest arrangement of Vus's array.
Examples
Note
In the first example, there is only one possible arrangement.
In the second example, other arrangements exist, such as or . However, all these arrangements are lexicographically larger than .
In the third example, no valid arrangement exists because the array will always have two adjacent ones.
Scoring
This problem uses post-test scoring with the following additional constraints:
( points):
( points):
( points):
( points):
( points):
( points):