#d2677. 弗拉德和糖果 II

弗拉德和糖果 II

Vlad and Candies II

Problem Description

Not long ago, Vlad celebrated his birthday and received a package of candies. There are nn types of candies, and the ii-th type has aia_i pieces (1≤i≤n1 \le i \le n).

Vlad decides to eat only one candy at a time. To get the most pleasure out of eating, Vlad does not want to eat two candies of the same type consecutively.

Help him figure out whether he can eat all the candies without ever eating two of the same type consecutively.

In short, given nn positive integers aia_i, where aia_i means there are aia_i copies of value ii, determine whether there exists a sequence that uses all the numbers with no two equal values adjacent.

Input Format

The first line contains an integer nn.

The second line contains nn positive integers.

Output Format

Output one line: if such a sequence exists, output YES; otherwise output NO.

Sample Input

2
1 1

Sample Output

YES

Sample Explanation

There are only two cases:

1 2
2 1

No matter which candy is eaten first, all candies can be finished without eating the same type consecutively.

Constraints

For 100%100\% of the data, 1≤n≤5 000 0001 \leq n \leq 5\,000\,000, 1≤ai≤2301 \leq a_i \leq 2^{30}.