#C5670. Rearranging Books

    ID: 49345 Type: Default 1000ms 256MiB

Rearranging Books

Rearranging Books

You are given a list of integers representing book identifiers. Your task is to rearrange the books such that no two consecutive identifiers are both even or both odd. Formally, if we denote the final sequence as (a_1, a_2, \ldots, a_n), then for every (1 \leq i < n), the parity of (a_i) must differ from the parity of (a_{i+1}). That is, one must be even and the other odd. If such a rearrangement is possible, output "YES" and the valid rearranged sequence; otherwise, output "NO". Note that if (|E - O| > 1) (where (E) is the number of even numbers and (O) is the number of odd numbers), then a valid rearrangement does not exist.

inputFormat

The input consists of two lines. The first line contains a single integer (n) ((1 \leq n \leq 10^5)) representing the number of books. The second line contains (n) space-separated integers representing the book identifiers.

outputFormat

If a valid rearrangement exists, output two lines. The first line must be "YES". The second line must contain the rearranged sequence of book identifiers separated by a single space. If no valid rearrangement exists, output a single line with "NO".## sample

5
3 8 5 12 7
YES

3 8 5 12 7

</p>