# Ouroboros sequence

0.6 The ouroboros is an ancient symbol depicting a snake eating its own
tail.

We will call a sequence of $n$ numbers $x_1$ ...$x_n$ an ouroboros if
two things happen:

1.  For every $1 \le i < n$, $x_i$ and $x_{i+1}$ differ by one.

2.  $x_n$ and $x_1$ also differ by one.

For instance, 3 4 5 4 3 2 1 2 is an ouroboros sequence, while 3 4 5 4 3
is not.

0.4

::: center
![image](ouroboros.eps){width="5.5cm"}
:::

Given a sequence of numbers, can you decide if they can be rearranged to
form an ouroboros sequence?

## Input

Input consists of several cases, each with $n$, followed by $x_1$
...$x_n$. Assume $2 \le n \le 10^5$, and that each $x_i$ is an integer
number between 0 and 1000.

## Output

Print one line for each case. If it is not possible to build an
ouroboros sequence from the given numbers, print "`NO`". Otherwise,
print "`YES`" followed by the lexicographically largest ouroboros
sequence.

## Problem information

Author: Joan Alemany

Generation: 2026-01-25T12:12:17.462Z

© *Jutge.org*, 2006--2026.\
<https://jutge.org>
