#arc118d. [arc118_d]Hamiltonian Cycle
[arc118_d]Hamiltonian Cycle
Problem Statement
Given are a prime number and positive integers and . Determine whether there is a sequence of integers, , satisfying all of the conditions below, and print one such sequence if it exists.
- .
- .
- is a permutation of .
- For every , at least one of the following holds.
Constraints
- is a prime.
Input
Input is given from Standard Input in the following format:
Output
If there is an integer sequence satisfying the conditions, print Yes
; otherwise, print No
. In the case of Yes
, print the elements in your sequence satisfying the requirement in the next line, with spaces in between.
If multiple sequences satisfy the requirement, any of them will be accepted.
Sample Input 1
13 4 5
Sample Output 1
Yes
1 5 11 3 12 9 7 4 6 8 2 10 1
This sequence satisfies the conditions, since we have the following modulo :
Sample Input 2
13 1 2
Sample Output 2
Yes
1 2 4 8 3 6 12 11 9 5 10 7 1
Sample Input 3
13 9 3
Sample Output 3
No
Sample Input 4
13 1 1
Sample Output 4
No