PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000187. Vlad và những viên kẹo (Vlad and Candies)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Vlad và những viên kẹo (Vlad and Candies)

Vlad and Candies

Source: Codeforces

Version: Phuoc Hung OJ (single-case adaptation where applicable)

Problem Statement

Vlad has nn types of candy, with aia_i candies of type ii. On each move he must eat one candy of a currently most frequent type; ties can be broken arbitrarily. He wants to eat all candies without taking the same type on two consecutive moves. Determine whether this is possible.

Input

Line 1 contains nn. Line 2 contains exactly nn positive integers a1,…,ana_1,\ldots,a_n.

Output

Print YES if such an eating order exists; otherwise print NO.

Subtasks

  • Subtask 1 (20 points): 1≤n≤151\le n\le 15; 1≤ai≤1001\le a_i\le 100 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤ai≤1000001\le a_i\le 100000 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤ai≤10000000001\le a_i\le 1000000000 for every 1≤i≤n1\le i\le n.

Examples

Example 1

Input

2
2 3

Output

YES

Explanation

Type 2 has three candies and is selected first. Then the two types can alternate until all candies are consumed.

Example 2

Input

3
1 4 1

Output

NO

Explanation

The most frequent type has four candies, exceeding the second largest count by three; after eating one, it remains the unique maximum and would have to be selected again.