Rearrange the given array of integers so that the sum of two adjacent elements is never divisible by three.
Input Specification
The first line contains an integer
Output Specification
If any valid rearrangement exists, output it on a single line. Otherwise, output impossible
.
Sample Input 1
Copy
3
1 2 3
Sample Output 1
Copy
2 3 1
Sample Input 2
Copy
5
4 6 3 9 8
Sample Output 2
Copy
3 4 6 8 9
Sample Input 3
Copy
6
3 7 6 4 2 8
Sample Output 3
Copy
3 7 4 6 2 8
Sample Input 4
Copy
3
3 12 9
Sample Output 4
Copy
impossible
Comments
Fun problem, taught me to think before rushing to submit.
It should be noted that you will WA on this question if you don't place a newline character after your line of output.
thanks