설명
Rearrange the given array of integers so that the sum of two adjacent elements is never divisible by
three.
제약
입력 형식
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\).
출력 형식
If any valid rearrangement exists, output it on a single line. Otherwise, output "impossible".
서브태스크
| 서브태스크 | 점수 | 설명 |
|---|---|---|
Subtask 1 | 100점 |
예제 1
입력
3
1 2 3출력
2 3 1예제 2
입력
5
4 6 3 9 8출력
3 4 6 8 9예제 3
입력
6
3 7 6 4 2 8출력
3 7 4 6 2 8예제 4
입력
3
3 12 9출력
impossible문제 정보
태그