题库练习 [COCI-2008_2009-contest6]#3 CUSKIJA
← 上一题 下一题 →

A1174 | [COCI-2008_2009-contest6]#3 CUSKIJA

来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0

题目描述

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 100000
0.

输出格式

If any valid rearrangement exists, output it on a single line. Otherwise, output "impossible".

输入输出样例

输入 #1
3 
1 2 3
输出 #1
2 3 1 
输入 #2
5 
4 6 3 9 8 
输出 #2
3 4 6 8 9
输入 #3
6 
3 7 6 4 2 8 
输出 #3
3 7 4 6 2 8 
C++ 编辑器
输入
输出