stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <cstdio>

#include <map>

using namespace std;



const int MN = 200005;



int N;

int A[MN];



map<int,int> B;

typedef map<int,int>::iterator IT;



bool check(int M) {

	B.clear();

//	printf("M = %d :\n", M);

	for (int i = 1; i <= N; ++i) {

		if (A[i - 1] >= A[i]) {

			int j = A[i];

			while (j && ++B[j] == M)

				B[j--] = 0;

			if (!j) return 0;

		}

		else {

			IT it = B.end();

			if (it != B.begin()) {

				--it;

				while (it->first > A[i - 1]) {

					IT tmp = it;

					if (it != B.begin()) --it, B.erase(tmp);

					else {B.erase(tmp); break;}

				}

			}

		}

//		for (int j = 1; j <= A[i]; ++j)

//			printf("%c", B[j] + 'a');

//		puts("");

	}

	return 1;

}



int main() {

	int ok = 1;

	scanf("%d", &N);

	for (int i = 1; i <= N; ++i) {

		scanf("%d", A + i);

		if (A[i - 1] >= A[i])

			ok = 0;

	}

	if (ok) return puts("1"), 0;

	int lb = 2, rb = N, mid, ans = -1;

	while (lb <= rb) {

		mid = lb + rb >> 1;

		if (check(mid)) ans = mid, rb = mid - 1;

		else lb = mid + 1;

	}

	printf("%d\n", ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.859335041380797x):
#include <cstdio>



const int MN = 200005;



int N, A[MN];



int stkp[MN], stkv[MN], tp;

inline bool check(int M) {

	tp = 0;

	for (int i = 1; i <= N; ++i) {

		if (A[i] <= A[i - 1]) {

			while (stkp[tp] > A[i]) --tp;

			int pos = A[i];

			while (pos) {

				if (stkp[tp] != pos || stkv[tp] != M - 1) {

					if (stkp[tp] != pos)

						stkp[++tp] = pos,

						stkv[tp] = 0;

					++stkv[tp];

					break;

				} else --tp, --pos;

			}

			if (!pos) return 0;

		}

	}

	return 1;

}



int main() {

	int ok = 1;

	scanf("%d", &N);

	for (int i = 1; i <= N; ++i) {

		scanf("%d", &A[i]);

		if (A[i] <= A[i - 1]) ok = 0;

	}

	if (ok) return puts("1"), 0;

	int lb = 2, rb = N, mid = 0, ans = 0;

	while (lb <= rb) {

		mid = (lb + rb) >> 1;

		if (check(mid)) ans = mid, rb = mid - 1;

		else lb = mid + 1;

	}

	printf("%d\n", ans);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int a[100005],n;

int v[100005];

int main()

{

	while(~scanf("%d",&n))

	{

		bool flag=0;int mi=1e9,ma=0;

		for(int i=1;i<=n;++i)

		{

			scanf("%d",&a[i]);

			mi=min(mi,a[i]);

			ma=max(ma,a[i]);

			v[a[i]]++;

			if(i>1&&a[i]!=a[i-1])flag=1;

		}

		if(ma-mi>1)puts("No");

		else if(!flag)

		{

			if(ma==n-1)puts("Yes");

			else

			{

				if(n/2>=mi)puts("Yes");

				else puts("No");

			}

		}

		else

		{

			if(v[mi]+v[ma]/2>=ma&&ma>v[mi])puts("Yes");

			else puts("No");

		}

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2004565117377775x):
#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#define MAXN 100005



int n;

int a[MAXN];

int ma,mi=(int)1e9;

int cnt;

int p;



int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		scanf("%d",a+i);

		ma=std::max(ma,a[i]);

		mi=std::min(mi,a[i]);

	}

	if(ma-mi>1||ma>n-1){

		p=0;

	}else if(ma==mi){

		if(ma==n-1) p=1;

		else if(ma*2<=n) p=1;

		else p=0; 

	}else{

		for(int i=1;i<=n;i++)

			if(a[i]==mi) cnt++;

		if(2*(ma-cnt)<=n-cnt&&ma>cnt) p=1;

		else p=0;

	}

	printf("%s\n",p?"Yes":"No");

}
// Slower C++ solution:
#include<cstdlib>

#include<iostream>

#include<cstring>

#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

int n,maxx=-1,minn=1e9;

int a[100010],num[100010];

bool flag=0;

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

	{

		scanf("%d",&a[i]);

		num[a[i]]++;

		maxx=max(maxx,a[i]);

		minn=min(minn,a[i]);

		if(a[i]!=a[i-1]&&i>=2)flag=1;

	}

	if(maxx-minn>1){printf("No");return 0;}

	if(flag)

	{

		if(2*(maxx-num[minn])<=num[maxx]&&maxx>num[minn])printf("Yes");

		else printf("No");

	}

	else

	{

		int x=a[1];

		if(x==1||x==n-1||x==n/2)printf("Yes");

		else printf("No");

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.202090363883034x):
#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#define MAXN 100005



int n;

int a[MAXN];

int ma,mi=(int)1e9;

int cnt;

int p;



int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		scanf("%d",a+i);

		ma=std::max(ma,a[i]);

		mi=std::min(mi,a[i]);

	}

	if(ma-mi>1||ma>n-1){

		p=0;

	}else if(ma==mi){

		if(ma==n-1) p=1;

		else if(ma*2<=n) p=1;

		else p=0; 

	}else{

		for(int i=1;i<=n;i++)

			if(a[i]==mi) cnt++;

		if(2*(ma-cnt)<=n-cnt&&ma>cnt) p=1;

		else p=0;

	}

	printf("%s\n",p?"Yes":"No");

}
// Slower C++ solution:
//... ...

#include<cstdio>

#include<cstring>

#include<iostream>

using namespace std;

const int M = 1e5 + 7;

int a[M];



int main() {

	int n;

	cin >> n;

	for(int i = 1 ; i <= n ; i++) cin >> a[i];

	int l = a[1] , r = a[1];

	for(int i = 2 ; i <= n ; i++) {

		l = min(a[i] , l);

		r = max(a[i] , r);

	}

	if(r - l > 1) cout << "No" << endl;

	else {

		if(l == r) {

			int gg = n - l;

			if(gg == 1) cout << "Yes" << endl;

			else {

				if(n == 1 || gg >= l) cout << "Yes" << endl;

				else cout << "No" << endl;

			}

		} else {

			int cnt1 = 0 , cnt2 = 0;

			for(int i = 1 ; i <= n ; i++) {

				if(a[i] == l) cnt1++;

				if(a[i] == r) cnt2++;

			}

			if(cnt1 >= r) cout << "No" << endl;

			else {

				int gg = n - r;

				if(gg >= r - cnt1) cout << "Yes" << endl;

				else cout << "No" << endl;

			}

		}

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.38755054160445x):
#include<cstdio>

inline int in();

inline void wr(int);

const int N=(int)1e5+5;

int a[N];

inline int mx(int,int);

inline int mn(int,int);

int main(int argc,char**argv){

#ifndef ONLINE_JUDGE

//	freopen("2386.in","r",stdin);

//	freopen("2386.ans","w",stdout);

#endif

	register int n=in();

	for(register int i=1;i<=n;++i)

		a[i]=in();

	register int x=0,y=n;

	for(register int i=1;i<=n;++i)

		x=mx(x,a[i]),y=mn(y,a[i]);

	if(x-y>1){puts("No");return 0;}

	if(!(x-y)){puts((x==n-1||(x<<1)<=n)?"Yes":"No");return 0;}

	register int m=0;

	for(register int i=1;i<=n;++i)

		m+=(a[i]==y);

	if(1+m<=x&&x<=m+((n-m)>>1))puts("Yes");

	else puts("No");

}

inline int mx(int x,int y){

	return x>y?x:y;

}

inline int mn(int x,int y){

	return x<y?x:y;

}

inline int in(){

	register char c=getchar();

	register int x=0,f=1;

	for(;c<'0'||c>'9';c=getchar())

		if(c=='-')f=-1;

	for(;c>='0'&&c<='9';c=getchar())

		x=(x<<1)+(x<<3)+(c&15);

	return x*f;

}

inline void wr(int x){

	if(x<0)putchar('-'),x=-x;

	if(x/10)wr(x/10);

	putchar(x%10+'0');

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int a[100010];

int main()

{

	int n,maxx=0,minn=1e9,t=0,sum=0;

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

		scanf("%d",a+i),maxx=max(maxx,a[i]),minn=min(minn,a[i]);

	if(maxx-minn>1)

	{

		puts("No");

		return 0;

	}

	if(maxx==minn&&minn==n-1)

	{

		puts("Yes");

		return 0;

	}

	for(int i=1;i<=n;i++)

		if(a[i]==maxx)t++;

		else sum++;

	if(sum>=maxx)

	{

		puts("No");

		return 0;

	}

	sum=maxx-sum;

	if(sum*2<=t)puts("Yes");

	else puts("No");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.309652557206921x):
#include<cstdio>

inline int in();

inline void wr(int);

const int N=(int)1e5+5;

int a[N];

inline int mx(int,int);

inline int mn(int,int);

int main(int argc,char**argv){

#ifndef ONLINE_JUDGE

//	freopen("2386.in","r",stdin);

//	freopen("2386.ans","w",stdout);

#endif

	register int n=in();

	for(register int i=1;i<=n;++i)

		a[i]=in();

	register int x=0,y=n;

	for(register int i=1;i<=n;++i)

		x=mx(x,a[i]),y=mn(y,a[i]);

	if(x-y>1){puts("No");return 0;}

	if(!(x-y)){puts((x==n-1||(x<<1)<=n)?"Yes":"No");return 0;}

	register int m=0;

	for(register int i=1;i<=n;++i)

		m+=(a[i]==y);

	if(1+m<=x&&x<=m+((n-m)>>1))puts("Yes");

	else puts("No");

}

inline int mx(int x,int y){

	return x>y?x:y;

}

inline int mn(int x,int y){

	return x<y?x:y;

}

inline int in(){

	register char c=getchar();

	register int x=0,f=1;

	for(;c<'0'||c>'9';c=getchar())

		if(c=='-')f=-1;

	for(;c>='0'&&c<='9';c=getchar())

		x=(x<<1)+(x<<3)+(c&15);

	return x*f;

}

inline void wr(int x){

	if(x<0)putchar('-'),x=-x;

	if(x/10)wr(x/10);

	putchar(x%10+'0');

}
// Slower C++ solution:
#include<iostream>

#include<cstring>

#include<cstdio>

using namespace std;

#define N 1000005

int n,a[N];

int maxx,minn;

int one,two;//unique 重名？！ 

int main(){

	maxx=0;minn=N;

	one=0;two=0;

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		scanf("%d",&a[i]);

		maxx=max(maxx,a[i]);

		minn=min(minn,a[i]);

	}

	if(maxx==minn){//correct 

		if(minn==n-1||minn<=n/2){

			printf("Yes\n");

		}else{

			printf("No\n");

		}

	}else if(maxx-minn>1||maxx>=n){

		printf("No\n");

	}else{

		for(int i=1;i<=n;i++){

			if(a[i]==minn) one++;

			else two++;

		}

		if(one>=maxx){//correct

			printf("No\n");

		}else if(one+two/2<maxx){

			printf("No\n");

		}else{

			printf("Yes\n");

		}

	}

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.308399110276384x):
#include<stdio.h>

#include<bits/locale_facets.h>

#include<algorithm>

using namespace std;

int a[100001];

long long input();

int main()

{

	int n=input(),total=0;

	for(int i=1;i<=n;i++)a[i]=input();

	sort(a+1,a+n+1);

	if(a[n]-a[1]>1||a[n]>=n)printf("No");

	else if(a[n]==a[1])

	{

		if(a[n]*2>n&&a[n]<n-1)printf("No");

		else printf("Yes");

	}

	else

	{

		for(int i=1;i<=n&&a[i]<a[n];i++)total++;

		if(0<a[n]-total&&2*a[n]<=n+total)printf("Yes");

		else printf("No");

	}

	return 0;

}

long long input()

{

	long long value=0,positive=1;

	char digit=getchar();

	for(;!isdigit(digit);digit=getchar())

	if(digit=='-')positive=-positive;

	for(;isdigit(digit);digit=getchar())value=(value<<3)+(value<<1)+digit-'0';

	return positive*value;

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define ll long long

#define ull unsigned long long

#define met(a, x) memset(a,x,sizeof(a));

#define inf 0x3f3f3f3f

#define mp make_pair;



using namespace std;

const int mod = 1e9 + 7;

const int N = 1e6 + 10;

const int M = 1e5 + 10;

int a[M + 10];



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int n;

    while (cin >> n) {

        for (int i = 1; i <= n; i++) {

            cin >> a[i];

        }

        sort(a + 1, a + 1 + n);

        if (a[n] - a[1] > 1||a[n]>=n) {

            cout << "No" << endl;

        } else {

            int cnt1 = 0, cnt2 = 0;

            for (int i = 1; i <= n; i++) {

                if (a[i] == a[n]) {

                    cnt2++;

                } else if (a[n] == a[i] + 1){

                    cnt1++;

                }

            }

            int cnt = cnt1 + cnt2 / 2;

            if (cnt1 == 0) {

                if (a[n] == n - 1 || 2*a[n]<=n) {

                    cout << "Yes" << endl;

                } else {

                    cout << "No" << endl;

                }

            } else {

                if (cnt >= a[n] && cnt2 != 1&&cnt1<a[n])

                    cout << "Yes" << endl;

                else

                    cout << "No" << endl;

            }

        }

    }

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.449939562383394x):
#include<stdio.h>

#include<bits/locale_facets.h>

#include<algorithm>

using namespace std;

int a[100001];

long long input();

int main()

{

	int n=input(),total=0;

	for(int i=1;i<=n;i++)a[i]=input();

	sort(a+1,a+n+1);

	if(a[n]-a[1]>1||a[n]>=n)printf("No");

	else if(a[n]==a[1])

	{

		if(a[n]*2>n&&a[n]<n-1)printf("No");

		else printf("Yes");

	}

	else

	{

		for(int i=1;i<=n&&a[i]<a[n];i++)total++;

		if(0<a[n]-total&&2*a[n]<=n+total)printf("Yes");

		else printf("No");

	}

	return 0;

}

long long input()

{

	long long value=0,positive=1;

	char digit=getchar();

	for(;!isdigit(digit);digit=getchar())

	if(digit=='-')positive=-positive;

	for(;isdigit(digit);digit=getchar())value=(value<<3)+(value<<1)+digit-'0';

	return positive*value;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int maxn=50005;

int a[100005],n;

int main()

{

    scanf("%d",&n);

    int mx=0;

    int mn=0x3f3f3f3f;

    for(int i=0;i<n;i++)

    {

        scanf("%d",&a[i]);

        mx=max(mx,a[i]);

        mn=min(mn,a[i]);

    }

    if(mx-1>mn)

    {

        printf("No\n");

        return 0;

    }

    if(mx==mn)

    {

        if(mn==n-1)

        {

            printf("Yes\n");

            return 0;

        }

        if(2*mn<=n)

        {

            printf("Yes\n");

            return 0;

        }

        else

        {

            printf("No\n");

            return 0;

        }

    }

    else

    {

        int ant=0;

        for(int i=0;i<n;i++)

        {

            if(a[i]==mn)

                ant++;

        }

        if(mn<ant)

        {

            printf("No\n");

            return 0;

        }

        if(n-ant<2*(mx-ant))

        {

            printf("No\n");

            return 0;

        }

        else

        {

            printf("Yes\n");

            return 0;

        }

    }

}


// Faster C++ solution for the same problem (measured speedup: 5.351688633589216x):
#include<stdio.h>

#include<bits/locale_facets.h>

#include<algorithm>

using namespace std;

int a[100001];

long long input();

int main()

{

	int n=input(),total=0;

	for(int i=1;i<=n;i++)a[i]=input();

	sort(a+1,a+n+1);

	if(a[n]-a[1]>1||a[n]>=n)printf("No");

	else if(a[n]==a[1])

	{

		if(a[n]*2>n&&a[n]<n-1)printf("No");

		else printf("Yes");

	}

	else

	{

		for(int i=1;i<=n&&a[i]<a[n];i++)total++;

		if(0<a[n]-total&&2*a[n]<=n+total)printf("Yes");

		else printf("No");

	}

	return 0;

}

long long input()

{

	long long value=0,positive=1;

	char digit=getchar();

	for(;!isdigit(digit);digit=getchar())

	if(digit=='-')positive=-positive;

	for(;isdigit(digit);digit=getchar())value=(value<<3)+(value<<1)+digit-'0';

	return positive*value;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)

#define REP(i,a) FOR(i,0,a)

	

using namespace std;



const int MAX_N=1e5;



int N,A[MAX_N];



int main(){

	cin>>N;

	int mx=0,mn=N;

	REP(i,N){

		cin>>A[i];

		mx=max(mx,A[i]);

		mn=min(mn,A[i]);

	}

	bool flg;

	if (mx-mn>1){

		flg=false;

	}else if (mx==mn){

		if (A[0]==N-1 || A[0]<=N/2){

			flg=true;

		}else{

			flg=false;

		}

	}else{

		int n1=0,n2=0;

		REP(i,N){

			if (A[i]==mx){

				n1++;

			}else{

				n2++;

			}

		}

		if (mx-n2>0 && mx-n2<=n1/2){

			flg=true;

		}else{

			flg=false;

		}

	}

	cout<<(flg ? "Yes"  : "No")<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.33950693671105x):
#include<complex>

#include<cstdio>

using namespace std;

const int N=1e6+7;

int n,minn=0x3f3f3f3f,maxn;

int a[N];

int qread()

{

	int x=0;

	char ch=getchar();

	while(ch<'0' || ch>'9')ch=getchar();

	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}

	return x;

}

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

	{

		a[i]=qread();

		maxn=max(maxn,a[i]);

		minn=min(minn,a[i]);

	}

	if(maxn-minn>=2){puts("No");return 0;;}

	if(maxn==minn)

	{

		if(minn==n-1)puts("Yes");

		else if(2*minn<=n)puts("Yes");

		else puts("No");

		return 0;

	}

	int cnt=0;

	for(int i=1;i<=n;i++)

		cnt+=a[i]==minn;

	if(minn<cnt)puts("No");

	else if(n-cnt<2*(maxn-cnt))puts("No");

	else puts("Yes");

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

int n;

int a[100100];

int ma,mi=0x3f3f3f3f;

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;++i)scanf("%d",&a[i]),ma=max(ma,a[i]),mi=min(mi,a[i]);

	if(ma-mi>=2)

	{

		puts("No");

		return 0;

	}

	int c=0;

	if(ma==mi)

	{

		if(mi==n-1||mi*2<=n)

			puts("Yes");

		else puts("No");

	}

	else

	{

		for(int i=1;i<=n;++i)

			if(a[i]==mi)c++;

		if(2*(mi+1-c)>n-c||ma-c<=0)

			puts("No");

		else puts("Yes");

	}

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.260855077434152x):
#include<complex>

#include<cstdio>

using namespace std;

const int N=1e6+7;

int n,minn=0x3f3f3f3f,maxn;

int a[N];

int qread()

{

	int x=0;

	char ch=getchar();

	while(ch<'0' || ch>'9')ch=getchar();

	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}

	return x;

}

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

	{

		a[i]=qread();

		maxn=max(maxn,a[i]);

		minn=min(minn,a[i]);

	}

	if(maxn-minn>=2){puts("No");return 0;;}

	if(maxn==minn)

	{

		if(minn==n-1)puts("Yes");

		else if(2*minn<=n)puts("Yes");

		else puts("No");

		return 0;

	}

	int cnt=0;

	for(int i=1;i<=n;i++)

		cnt+=a[i]==minn;

	if(minn<cnt)puts("No");

	else if(n-cnt<2*(maxn-cnt))puts("No");

	else puts("Yes");

	return 0;

}
// Slower C++ solution:
#include <string>

#include <ctype.h>

#include <stdio.h>

#include <string.h>

#include <iostream>

#include <algorithm>

const int inf = 0x3f3f3f3f;

char buf[(1 << 22)], *p1 = buf, *p2 = buf;

#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)

inline int read() {

    char c = getchar(); int x = 0;

    for (;not isdigit(c); c = getchar());

    for (;isdigit(c); x = x * 10 + c - '0', c = getchar());

    return x;

}



int main () {

    int T;

    // T = read();/

    T = 1;

    while (T--) {

        int n; bool flag = 0;

        n = read();

        int Min = inf, Max = 0;

        int sizMi = 0, sizMa = 0;

        for (int i = 1, tmp; i <= n; i += 1) {

            tmp = read();

            Min = tmp < Min ? sizMi = 0, tmp : Min;

            Max = tmp > Max ? sizMa = 0, tmp : Max;

            sizMi += tmp == Min ? 1 : 0, sizMa += tmp == Max ? 1 : 0;

        }

        if (Min == Max and Min == n - 1) {

        	printf("Yes\n");

        	continue;

        }

        if (Min == Max) sizMi = 0;

        int ZhiShao = sizMi + 1;

        int ZhiDuo = sizMa / 2 + sizMi;

        if (Max < ZhiShao or Max > ZhiDuo) flag = true;

        if (Min < Max - 1) flag = true;

        printf("%s\n", not flag ? "Yes" : "No");

    }

    return 0;

}



/*

analyse:

    If a_max > a_min + 1, it must be false;

    If a_i = a_j - 1, means Size_a_i = 1, Size_a_j > 1, Col_a_i not equal Col_a_j;

    If a_i = a_j, means Size_a_i = 1 and Size_a_j = 1 or Size_a_i > 1 and Size_a_j > 1;

    

    All in all, 

    Note the num of the a_min is A, the num of the a_max if B;

    If n - A < B, is must be false;

*/


// Faster C++ solution for the same problem (measured speedup: 5.256887690354043x):
#include<complex>

#include<cstdio>

using namespace std;

const int N=1e6+7;

int n,minn=0x3f3f3f3f,maxn;

int a[N];

int qread()

{

	int x=0;

	char ch=getchar();

	while(ch<'0' || ch>'9')ch=getchar();

	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}

	return x;

}

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

	{

		a[i]=qread();

		maxn=max(maxn,a[i]);

		minn=min(minn,a[i]);

	}

	if(maxn-minn>=2){puts("No");return 0;;}

	if(maxn==minn)

	{

		if(minn==n-1)puts("Yes");

		else if(2*minn<=n)puts("Yes");

		else puts("No");

		return 0;

	}

	int cnt=0;

	for(int i=1;i<=n;i++)

		cnt+=a[i]==minn;

	if(minn<cnt)puts("No");

	else if(n-cnt<2*(maxn-cnt))puts("No");

	else puts("Yes");

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstring>

#include<cmath>

#include<cstdio>

#include<algorithm>

using namespace std;

const int maxn=100010,inf=1000000000;

int n,a[maxn],maxa,mina,tot;

int main(){

	cin>>n;mina=inf;

	for(int i=1;i<=n;++i){

		scanf("%d",&a[i]);

		maxa=max(maxa,a[i]);

		if(a[i]<mina)mina=a[i],tot=0;

		if(a[i]==mina)tot++;

	}

	//cout<<mina<<' '<<tot<<' '<<maxa<<endl;

	if(maxa-mina>1)puts("No");

	else{

		if(maxa==mina){

			if(maxa<=n/2||maxa==n-1)puts("Yes");

			else puts("No");

		}

		else{

			if((maxa-tot>0)&&(maxa-tot)<=(n-tot)/2)puts("Yes");

			else puts("No");

		}

	}

	//system("pause");

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.285826639848328x):
#include<cstdio>

using namespace std;

int a[100005];

int cnt[2][100005];

int main(){

	int n;

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		scanf("%d",&a[i]);

		cnt[0][a[i]]++;

		cnt[1][a[i]]++;

	}

	int ok=0,sum;

	int remain;

	sum=n-1;

	remain=n-1-a[1];

	cnt[0][a[1]]-=1;

	if(remain>=0&&cnt[0][a[1]]>=remain){

		sum-=remain;

		cnt[0][a[1]]-=remain;

		remain+=1;

		if(cnt[0][a[1]-1]+cnt[0][a[1]]==sum&&cnt[0][a[1]]<=remain&&cnt[0][a[1]]>0){

			ok=1;

			//printf("!\n");

		}

	}

	

	sum=n-1;

	remain=n-1-a[1];

	cnt[1][a[1]]-=1;

	if(remain>=0&&cnt[1][a[1]+1]>=remain){

		sum-=remain;

		cnt[1][a[1]+1]-=remain;

		if(cnt[1][a[1]+1]+cnt[1][a[1]]==sum&&cnt[1][a[1]+1]<=remain&&(cnt[1][a[1]+1]>0&&remain>0||cnt[1][a[1]+1]==0&&remain==0)){

			ok=1;

			//printf("?\n");

		}

	}

	

	if(ok)

		printf("Yes\n");

	else

		printf("No\n");

	

	

}
// Slower C++ solution:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

 

using namespace std;

using namespace __gnu_pbds;

 

#define fi first

#define se second

#define mp make_pair

#define pb push_back

#define fbo find_by_order

#define ook order_of_key

 

typedef long long ll;

typedef pair<ll,ll> ii;

typedef vector<ll> vi;

typedef long double ld; 

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

typedef set<ll>::iterator sit;

typedef map<ll,ll>::iterator mit;



int a[100001];



int main()

{

	ios_base::sync_with_stdio(0); cin.tie(0);

	int n; cin>>n;

	int mini=n;

	int maxi=0;

	for(int i=0;i<n;i++) 

	{

		cin>>a[i];

		mini=min(mini,a[i]);

		maxi=max(maxi,a[i]);

	}

	if(maxi-mini<=1)

	{

		int s = 0; int b = 0;

		for(int i=0;i<n;i++)

		{

			if(a[i]==maxi)

			{

				b++;

			}

			else if(a[i]==maxi-1)

			{

				s++;

			}

		}

		if(b==1)

		{

			cout<<"No\n";

			return 0;

		}

		if(s==0&&maxi==n-1)

		{

			cout<<"Yes\n";

			return 0;

		}

		//from here b >= 2

		//there must be s extra unique colors

		//n - s

		int l = s + 1;

		int r = s + (n-s)/2;

		if(maxi>=l&&maxi<=r) cout<<"Yes\n";

		else cout<<"No\n";

	}

	else

	{

		cout<<"No\n";

	}

}


// Faster C++ solution for the same problem (measured speedup: 5.360642819349666x):
#include<cstdio>

using namespace std;

int a[100005];

int cnt[2][100005];

int main(){

	int n;

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		scanf("%d",&a[i]);

		cnt[0][a[i]]++;

		cnt[1][a[i]]++;

	}

	int ok=0,sum;

	int remain;

	sum=n-1;

	remain=n-1-a[1];

	cnt[0][a[1]]-=1;

	if(remain>=0&&cnt[0][a[1]]>=remain){

		sum-=remain;

		cnt[0][a[1]]-=remain;

		remain+=1;

		if(cnt[0][a[1]-1]+cnt[0][a[1]]==sum&&cnt[0][a[1]]<=remain&&cnt[0][a[1]]>0){

			ok=1;

			//printf("!\n");

		}

	}

	

	sum=n-1;

	remain=n-1-a[1];

	cnt[1][a[1]]-=1;

	if(remain>=0&&cnt[1][a[1]+1]>=remain){

		sum-=remain;

		cnt[1][a[1]+1]-=remain;

		if(cnt[1][a[1]+1]+cnt[1][a[1]]==sum&&cnt[1][a[1]+1]<=remain&&(cnt[1][a[1]+1]>0&&remain>0||cnt[1][a[1]+1]==0&&remain==0)){

			ok=1;

			//printf("?\n");

		}

	}

	

	if(ok)

		printf("Yes\n");

	else

		printf("No\n");

	

	

}