410782: GYM104103 C Password Lock
Description
Andrey got a cool new lock for his birthday. You can set several passwords on it at the same time; when you enter any of them, the lock opens.
The lock consists of a sequence of cells, each has an integer written on it. You can swap places of any two cells any number of times; when they are arranged in any correct order, the lock opens. The order is considered correct when the sum of two integers on any pair of adjacent cells is not divisible by $$$k$$$.
You found out about the structure of this lock and, of course, decided to try to open it. Given the numbers on the cells and the value of $$$k$$$, find the permutation of cells that opens the lock.
InputThe first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le k \le 10^9$$$) — the number of cells on the lock and the number $$$k$$$.
The second line of the input contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — the initial configuration of cells on the lock.
OutputIf there is no suitable permutation of cells, print "NO" (without quotes, case insensitive) on the first line.
If a suitable permutation of cells exists, print "YES" (no quotes, case insensitive) on the first line. In the second line, print $$$n$$$ integers — the permutation itself.
ScoringSubtask | Points | Constraints |
$$$1$$$ | $$$8$$$ | $$$n \le 8$$$ |
$$$2$$$ | $$$8$$$ | $$$k = 2$$$ |
$$$3$$$ | $$$8$$$ | $$$k = 3$$$ |
$$$4$$$ | $$$8$$$ | $$$n = k$$$; numbers $$$a_i$$$ are distinct and are between $$$1$$$ and $$$n$$$ |
$$$5$$$ | $$$25$$$ | $$$k$$$ is odd |
$$$6$$$ | $$$43$$$ | No additional restrictions |
3 4 1 3 2Output
YES 1 2 3Input
5 4 1 2 2 2 4Output
YES 2 4 2 1 2