P29167 [洛谷] [COCI2008-2009#6] CUSKIJA
提高-
题目描述

Problem Description

Given a sequence \( a \) of length \( n \), please rearrange it such that the sum of any two adjacent numbers in the new sequence is not divisible by 3.

Input Format

The first line contains an integer representing the length of the sequence \( n \).

The second line contains \( n \) integers, where the \( i \)-th integer represents the \( i \)-th element of the sequence \( a_i \).

Output Format

This problem includes a Special Judge.

  • If a solution exists, output a string Yes on the first line, followed by \( n \) integers on the second line, where the \( i \)-th integer represents the \( i \)-th element of the new sequence.
  • If no solution exists, output a string No on a single line.

Sample Input and Output

Sample Input #1

3
1 2 3

Sample Output #1

Yes
2 3 1

Sample Input #2

5
4 6 3 9 8

Sample Output #2

Yes
3 4 6 8 9

Sample Input #3

6
3 7 6 4 2 8

Sample Output #3

Yes
3 7 4 6 2 8

Sample Input #4

3
3 12 9

Sample Output #4

No

Notes

Data Size and Constraints

For all test cases, it is guaranteed that \( 1 \leq n \leq 10^4 \) and \( 1 \leq a_i \leq 10^6 \).

Explanation

The problem is translated from COCI2008-2009 CONTEST #6 T4 CUSKIJA, with translation and SPJ provided by @一扶苏一. The output format has been slightly modified for SPJ convenience.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 1 2 3
样例输出
Yes 2 3 1