#K37442. Taco Rearrangement

    ID: 25977 Type: Default 1000ms 256MiB

Taco Rearrangement

Taco Rearrangement

You are given an array arr consisting of elements that can only be -1, 0, or 1. Your task is to determine if it is possible to rearrange the array so that for every pair of adjacent elements, the following condition holds:

$$a_i + a_{i+1} \ge -1$$

If such a rearrangement exists, print YES; otherwise, print NO.

Note: In particular, if the array contains more than one occurrence of -1 and does not contain any 1, then it is impossible to avoid having two adjacent -1's whose sum is -2, which violates the condition.

inputFormat

The input consists of two lines:

  • The first line contains a single integer n representing the length of the array.
  • The second line contains n space-separated integers, each of which is -1, 0, or 1.

outputFormat

Output a single line containing either YES or NO based on whether a valid rearrangement exists.

## sample
5
1 -1 0 1 -1
YES

</p>