测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

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

编程题 普及/提高-

题目描述

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 
上一题 去做题 下一题