#C9717. Lantern Arrangement
Lantern Arrangement
Lantern Arrangement
In the mythical land of Pyroland, the annual Lantern Festival is celebrated with a curious tradition. The participants are given lanterns of various heights, and they must arrange these lanterns into a sequence that alternates between peaks and troughs. Specifically, for any lantern positioned at index \(i\) (where \(1 \le i \le n-2\)), it must satisfy one of the following conditions:
- Peak: \(a_i > a_{i-1}\) and \(a_i > a_{i+1}\)
- Trough: \(a_i < a_{i-1}\) and \(a_i < a_{i+1}\)
If such an arrangement exists, output the valid sequence. Otherwise, output "Impossible".
inputFormat
The first line contains a positive integer \(n\) representing the number of lanterns.
The second line contains \(n\) space-separated integers representing the heights of the lanterns.
outputFormat
If an alternating arrangement exists, output the rearranged sequence as space-separated integers in one line. If no valid arrangement exists, output "Impossible".
## sample3
2 3 1
2 3 1