After dealing with his
- It starts and ends with
, - Adjacent elements have a maximum difference of
, - There is
maximum number and peaks at that number, - It is non-decreasing before the peak and is non-increasing after the peak.
Help Bob re-order his array into a temple!
Input Specification
The first line will contain
The next line will contain
Output Specification
Output
If there are multiple valid solutions, output the lexicographically largest one.
Note: It is guaranteed that there is at least one valid solution.
Sample Input 1
Copy
5
1 3 2 2 1
Sample Output 1
Copy
1 2 3 2 1
Sample Input 2
Copy
11
1 1 2 2 2 3 4 5 4 3 4
Sample Output 2
Copy
1 2 3 4 5 4 4 3 2 2 1
Note: There are multiple valid solutions for this case, but this is the lexicographically largest one.
Comments