#P6470. [COCI 2008/2009 #6] CUSKIJA
[COCI 2008/2009 #6] CUSKIJA
Description
Given a sequence of length , reorder it so that in the new sequence, the sum of any two adjacent numbers is not divisible by .
Input Format
The first line contains an integer , the length of the sequence.
The second line contains integers. The -th integer is the -th element of the sequence, .
Output Format
This problem uses Special Judge.
- If a solution exists, output a string
Yeson the first line, and on the second line output integers, where the -th integer is the -th element of the new sequence. - If no solution exists, output only a string
Noon one line.
3
1 2 3
Yes
2 3 1
5
4 6 3 9 8
Yes
3 4 6 8 9
6
3 7 6 4 2 8
Yes
3 7 4 6 2 8
3
3 12 9
No
Hint
Constraints
For all testdata, it is guaranteed that and .
[Notes]
This problem is translated from COCI2008-2009 CONTEST #6 T4 CUSKIJA. The translation and SPJ are provided by @一扶苏一. For easier SPJ checking, the output format is slightly modified compared to the original problem.
Translated by ChatGPT 5
京公网安备 11011102002149号