Rearrange the given array of integers so that the sum of two adjacent elements is never divisible by three.
Input
The first line contains an integer $N$ ($1 \le N \le 10000$), the number of elements in the array.
The second line contains the elements of the array separated by single spaces. The elements will be positive integers less than $1000000$.
Output
If any valid rearrangement exists, output it on a single line. Otherwise, output "impossible".
Example 1
Input
3 1 2 3
Output
2 3 1
Example 2
Input
5 4 6 3 9 8
Output
3 4 6 8 9
Example 3
Input
6 3 7 6 4 2 8
Output
3 7 4 6 2 8
Example 4
Input
3 3 12 9
Output
impossible
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.