Problem:
Score : 700 points

Problem Statement

There are N cats.
We number them from 1 through N.

Each of the cats wears a hat.
Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."

Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.

Constraints

2 ≤ N ≤ 10^5

1 ≤ a_i ≤ N-1

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print Yes if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print No otherwise.

Sample Input 1

3
1 2 2

Sample Output 1

Yes

For example, if cat 1, 2 and 3 wears red, blue and blue hats, respectively, it is consistent with the remarks of the cats.

Sample Input 2

3
1 1 2

Sample Output 2

No

From the remark of cat 1, we can see that cat 2 and 3 wear hats of the same color.
Also, from the remark of cat 2, we can see that cat 1 and 3 wear hats of the same color.
Therefore, cat 1 and 2 wear hats of the same color, which contradicts the remark of cat 3.

Sample Input 3

5
4 3 4 3 4

Sample Output 3

No

Sample Input 4

3
2 2 2

Sample Output 4

Yes

Sample Input 5

4
2 2 2 2

Sample Output 5

Yes

Sample Input 6

5
3 3 3 3 3

Sample Output 6

No

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

/*
700分的题就这么神仙了么。。好难啊。。。

先说结论吧

设$mx, mn$分别为最大 / 最小值，显然$mx - mn > 1$的时候无解

接下来分两种情况讨论

$mx = mn$：这时候每一种颜色要么是互不相同，要么是至少出现两次

$mx = mn +1$：这时候小的元素一定是独一无二的，大的元素至少出现两次。

以上结论都可以用反证法证明。


总结：
虽然结论证起来不难，但是自己想的话确实是太难受了，因为会有很多干扰你的模型(我最开始的时候还想tarjan缩点来着qwq)。
自己推了一个多小时也刚刚推除了无解的情况和$mx = mn$的情况，推到最后直接心态爆炸，我甚至都感觉自己的思路有问题，
因为每个结论要证明都不是很显然，总是感觉自己想复杂了。不过这题确实是好题
*/
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 10;
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int N, a[MAXN];
main() {
	N = read();
	for(int i = 1; i <= N; i++) a[i] = read();
	sort(a + 1, a + N + 1);
	int mn = 0, mx = 0, num;
	a[0] = -1;
	for(int i = 1; i <= N; i++) 
		if(a[i] != a[i - 1]) {
			if(!mn) mn = a[i];
			else if(!mx) mx = a[i], num = i - 1;
			else {puts("No"); return 0;}
		}
	if(!mx) {
		if((mn == N - 1) || (mn * 2 <= N)) puts("Yes");
		else puts("No");
	} else {
		if((mx == mn + 1) && (2 * (mx - num) <= N - num) && (mx - num > 0)) puts("Yes");
		else puts("No");
	}
	return 0;
}
/*

*/