#K13941. Consecutive Arrangement
Consecutive Arrangement
Consecutive Arrangement
Given an array of integers, determine if it is possible to rearrange the array such that the absolute difference between every pair of consecutive integers is exactly 1. In other words, check if there exists a permutation \(b_1, b_2, \ldots, b_N\) of the array \(a_1, a_2, \ldots, a_N\) satisfying \(|b_i - b_{i-1}| = 1\) for every \(2 \leq i \leq N\). If the array meets the condition, output "Yes" on the first line and the rearranged (sorted) array on the second line. Otherwise, output "No". Note that if the array has only one element, the answer is always "Yes".
inputFormat
The input is given via standard input. The first line contains an integer \(N\) (\(1 \leq N \leq 10^5\)), representing the number of elements in the array. The second line contains \(N\) space-separated integers, each with an absolute value of at most \(10^9\).
outputFormat
If the array can be rearranged to satisfy the condition, print two lines: the first line must be "Yes" and the second line must be the rearranged array (in non-decreasing order) with a single space between adjacent integers. Otherwise, print "No".
## sample5
1 3 2 4 5
Yes
1 2 3 4 5
</p>