#K14621. Harmonic List Rearrangement
Harmonic List Rearrangement
Harmonic List Rearrangement
Given a list of n integers, determine if it is possible to rearrange the list so that the absolute difference between every two consecutive elements is at most 1. In other words, if the rearranged list is \(a_1, a_2, \ldots, a_n\), then for every valid index \(i\) (1 ≤ \(i < n\)) the inequality \(|a_{i+1} - a_i| \le 1\) must hold.
If such an arrangement exists, print "Yes"; otherwise, print "No".
The input is read from standard input and the output should be printed to standard output.
inputFormat
The first line contains a single integer \(n\) (1 ≤ \(n\) ≤ 105), which represents the number of integers in the list.
The second line contains \(n\) space-separated integers. Each integer \(a_i\) may be within the range \(|a_i| \le 10^9\).
outputFormat
Output a single line: "Yes" if the list can be rearranged to form a harmonic list, and "No" otherwise.
## sample4
1 2 1 2
Yes