CUSKIJA
시간 제한: 1000ms메모리 제한: 128MB출처: COCI 2008-2009BOJ 2938
문제
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 ≤ N ≤ 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 "-1".
예제
예제 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
출력
-1
코드를 제출하려면 로그인하세요.