stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int mod= 998244353;

int D[100005];

int num[100005];

ll multi(ll a,ll b,ll mod){

	ll ans=0;

	while(b){

		if(b&1)

			ans=(ans+a)%mod;

		a=(a<<1)%mod;

		b>>=1;

	}

	return ans;

}

ll qpow(ll a,ll b,ll mod){

	ll ans=1;

	while(b){

		if(b&1)

			ans=multi(ans,a,mod);

		a=multi(a,a,mod);

		b>>=1;

	}

	return ans;

}

int main(){

	int n;

	scanf("%d",&n);

	int m=0;

	memset(num,0,sizeof num);

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

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

		m=max(m,D[i]);

		num[D[i]]++;

	}

	if(num[0]!=1||D[0]!=0){

		printf("0");

		return 0;

	}

	ll ans=1;

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

		if(num[i]==0){

			ans=0;

			break;

		}

		ans=ans*qpow(num[i-1],num[i],mod)%mod;

	}

	printf("%lld",(ans+mod)%mod);

}

// Faster C++ solution for the same problem (measured speedup: 1.3880303993759646x):
#pragma GCC optimize(2) 

#include<iostream>

#include<algorithm>

using namespace std;

const int mod=998244353;

long long a[100010];

long long n,x;

long long ksm(long long a,long long b){

	long long res=1;

	while(b){

		if(b&1){

			res*=a;

			res%=mod;

		}

		a*=a;

		a%=mod;

		b>>=1;

	}

	return res;

}

 

int main(){

	//scanf("%lld",&n);

	cin>>n;

	int flag=0;

//	scanf("%lld",&x);

	cin>>x;

	long long  ans=x;

	if(x!=0) flag=1;

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

//		scanf("%lld",&x);

		cin>>x;

		a[x]++;

		if(x==0) flag=1;

		ans=max(ans,x);

	}

	if(flag){

	//	printf("0\n");

		cout<<0<<"\n";

	}

	else{

	long long sum=1;

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

			if(a[i]==0){

				flag=1;

				break;

			}

			sum*=ksm(a[i],a[i+1]);

			sum%=mod;

		}

		if(flag) cout<<0<<"\n";//printf("0\n");

		else  cout<<sum<<"\n";//printf("%lld\n",sum);

	}

	return 0;

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

using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 10;



ll d[MAXN], s[MAXN];



ll quick_pow(ll a, ll b, ll mod) {

	ll ans = 1;

	while(b) {

		if(b & 1) {

			ans = ans * a % mod;

		}

		a = a * a % mod;

		b >>= 1;

	}

	return ans;

}



int main() {

	ios::sync_with_stdio(false);

	ll n, num, mod = 998244353;

	while(cin >> n) {

		ll maxd = -1;

		memset(d, 0, sizeof(d));

		memset(s, 0, sizeof(s));

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

			cin >> num;

			s[i] = num;

			d[num]++;

			maxd = max(maxd, num);

		}

		ll ans;

		if(s[0] != 0 || d[0] != 1) {

			ans = 0;

		} else if(n == 1) {

			if(d[0] == 1 && s[0] == 0) {

				ans = 1;

			} else {

				ans = 0;

			}

		} else {

			ans = 1;

			for(int i = 0; i <= maxd; i++) {

				ans = ans * quick_pow(d[i], d[i + 1], mod) % mod;

			}

		}

		cout << ans << endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.617686945210271x):
#pragma GCC optimize(2) 

#include<iostream>

#include<algorithm>

using namespace std;

const int mod=998244353;

long long a[100010];

long long n,x;

long long ksm(long long a,long long b){

	long long res=1;

	while(b){

		if(b&1){

			res*=a;

			res%=mod;

		}

		a*=a;

		a%=mod;

		b>>=1;

	}

	return res;

}

 

int main(){

	//scanf("%lld",&n);

	cin>>n;

	int flag=0;

//	scanf("%lld",&x);

	cin>>x;

	long long  ans=x;

	if(x!=0) flag=1;

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

//		scanf("%lld",&x);

		cin>>x;

		a[x]++;

		if(x==0) flag=1;

		ans=max(ans,x);

	}

	if(flag){

	//	printf("0\n");

		cout<<0<<"\n";

	}

	else{

	long long sum=1;

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

			if(a[i]==0){

				flag=1;

				break;

			}

			sum*=ksm(a[i],a[i+1]);

			sum%=mod;

		}

		if(flag) cout<<0<<"\n";//printf("0\n");

		else  cout<<sum<<"\n";//printf("%lld\n",sum);

	}

	return 0;

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

#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

const int maxn=998244353;

typedef long long ll;

int main()

{

	ll n,c,sum,ans;

	ll a[100006],vis[100006];

	scanf("%lld",&n);

	memset(vis,0,sizeof(vis));

	c=-1;

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

	{

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

		if(c<a[i])

		{

			c=a[i];

		}

	}

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

	{

		vis[a[i]]++;

		if(i==1)

		{

			if(a[i]>0)

			{

				printf("0\n");

				return 0;

			}

		}

		else

		{

			if(a[i]==0)

			{

				printf("0\n");

				return 0;

			}

		}

	}

	for(ll i=1;i<=c;i++)

	{

		if(i==1)

		{

			sum=1;

		}

		else

		{

			ans=1;

			for(ll j=1;j<=vis[i];j++)

			{

				ans=ans*vis[i-1]%maxn;

			}

			sum=sum*ans%maxn;

		}

	}

	printf("%lld\n",sum);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8175540135960153x):
#pragma GCC optimize(2) 

#include<iostream>

#include<algorithm>

using namespace std;

const int mod=998244353;

long long a[100010];

long long n,x;

long long ksm(long long a,long long b){

	long long res=1;

	while(b){

		if(b&1){

			res*=a;

			res%=mod;

		}

		a*=a;

		a%=mod;

		b>>=1;

	}

	return res;

}

 

int main(){

	//scanf("%lld",&n);

	cin>>n;

	int flag=0;

//	scanf("%lld",&x);

	cin>>x;

	long long  ans=x;

	if(x!=0) flag=1;

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

//		scanf("%lld",&x);

		cin>>x;

		a[x]++;

		if(x==0) flag=1;

		ans=max(ans,x);

	}

	if(flag){

	//	printf("0\n");

		cout<<0<<"\n";

	}

	else{

	long long sum=1;

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

			if(a[i]==0){

				flag=1;

				break;

			}

			sum*=ksm(a[i],a[i+1]);

			sum%=mod;

		}

		if(flag) cout<<0<<"\n";//printf("0\n");

		else  cout<<sum<<"\n";//printf("%lld\n",sum);

	}

	return 0;

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

    #include <iostream>

    using namespace std;

     

    int main()

    {

      int N; cin >> N;

      long cnt[100005] = {};

      int D[100005] = {};

      int mx_D = 0;

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

      {

        cin >> D[i];

        mx_D = max(mx_D, D[i]);

        cnt[D[i]]++;

      }

      

      if (cnt[0] != 1 || D[0] != 0)

      {

        cout << 0 << endl;

        return 0;

      }

      

      long ans = 1;

      long mod = 998244353;

      

      for (int j = 1; j <= mx_D; j++)

      {

        for (int k = 0; k < cnt[j]; k++)

        {

          ans *= cnt[j - 1];

          ans %= mod;

        }

      }

      

      cout << ans << endl;

      return 0;

    }

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

using namespace std;

int main(){

	int N,dir,D[100005]={0},maxD=0;

	long long sum;

	cin>>N;

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

		cin>>dir;

		if(i==0&&dir!=0){

			cout<<0;

			return 0;

		}	

      	if(dir>maxD)maxD=dir;

		D[dir]++;

	}

	if(D[0]!=1){

		cout<<0;

		return 0;

	}

    long mod = 998244353;

	sum=1;

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

		if(D[i]!=0){

			for (int j=0;j<D[i];j++){

				sum*=D[i-1];

				sum%=mod;

			}

		}else{

			sum=0;

			break;

		}

	}

	cout<<sum;

	return 0;

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

    #include <iostream>

    using namespace std;

     

    int main()

    {

      int N; cin >> N;

      long cnt[100005] = {};

      int D[100005] = {};

      int mx_D = 0;

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

      {

        cin >> D[i];

        mx_D = max(mx_D, D[i]);

        cnt[D[i]]++;

      }

      

      if (cnt[0] != 1 || D[0] != 0)

      {

        cout << 0 << endl;

        return 0;

      }

      

      long ans = 1;

      long mod = 998244353;

      

      for (int j = 1; j <= mx_D; j++)

      {

        for (int k = 0; k < cnt[j]; k++)

        {

          ans *= cnt[j - 1];

          ans %= mod;

        }

      }

      

      cout << ans << endl;

      return 0;

    }

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

    using namespace std;

    int main(){

    	int N,dir,D[100000]={0},maxD=0;

    	long long sum;

    	cin>>N>>dir;

    	if(dir!=0){

    		cout<<0;

    		return 0;

    	}

    	D[0]=1;

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

    		cin>>dir;

    		if(dir>maxD)maxD=dir;

    		D[dir]++;

    	}

    	if(D[0]!=1){

    		cout<<0;

    		return 0;

    	}

    	sum=D[0];

    	for(long i=2;i<=maxD;i++){

    		if(D[i]!=0){

    			for(int j=0;j<D[i];j++){

    				sum*=D[i-1];

    				sum%=998244353LL;

    			}

    		}else{

    			sum=0;

    			break;

    		}

    	}

    	cout<<sum;

    	return 0;

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

using namespace std;

typedef long long ll;

const ll mod=998244353;

ll ksm(ll a,ll b)

{

	ll ans=1;

	while(b)

	{

		if(b&1) ans=ans*a%mod;

		b/=2;

		a=a*a%mod;

	}

	return ans;

}

int main()

{

	ll n,x,ans=1,s[100100],num[100100];

	memset(num,0,sizeof num);

	cin>>n;

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

	{

		cin>>x;

		if(!i&&x) ans=0;

		else if(i&&!x) ans=0;

		num[x]++;

	}

	if(ans)

	{

//		ans=num[1];

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

			if(num[i]&&num[i-1])

				ans=ans*ksm(num[i-1],num[i])%mod;

			else if(num[i]&&!num[i-1]) ans=0;

	}

	cout<<ans;

	return 0;

}

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

#include<iostream>

#include<cmath>

#include<algorithm>

#include<cstring>

#include<cctype>

#include<vector>

#include<stack>

#include<queue>

#include<ctime>

#include<map>

#define ll long long

#define ld long double

#define ull unsigned long long

using namespace std;

const ll mod = 998244353;

const int maxn = 101001;

ll a[maxn];

ll mul(ll x,ll y,ll z)

{

    ll sm = (ld)x/z*y;

    return ((ull)x*y-(ull)sm*z+z)%z;

}

ll qpow(ll x,ll y,ll z)

{

    ll ans = 1;

    x %= z;

    for(ll i=y;i;i>>=1){

        if(i&1) ans = mul(ans,x,z);

        x = mul(x,x,z);

    }

    return ans%z;

}

int main(void)

{

    int n,x;

    scanf("%d",&n);

    cin>>x;	//判断首位是否为0

    if(x!=0){

        printf("0\n");

        return 0;

    }

    a[x]++;

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

        scanf("%d",&x);

        a[x]++;

    }

    if(a[0]>1){	//判断是否多个0

        printf("0\n");

        return 0;

    }

    int ret = 0;

    ll ans = 1,pr = 1;

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

        if(a[i]==0){	//判断是否有间隔

            if(ret!=n)  ans = 0;

            break;

        }

        ans = mul(ans,qpow(pr,a[i],mod),mod);

        pr = a[i];

        ret += (int)a[i];

    }

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

    return 0;

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

using namespace std;

typedef long long ll;

const ll mod=998244353;

ll ksm(ll a,ll b)

{

	ll ans=1;

	while(b)

	{

		if(b&1) ans=ans*a%mod;

		b/=2;

		a=a*a%mod;

	}

	return ans;

}

int main()

{

	ll n,x,ans=1,s[100100],num[100100];

	memset(num,0,sizeof num);

	cin>>n;

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

	{

		cin>>x;

		if(!i&&x) ans=0;

		else if(i&&!x) ans=0;

		num[x]++;

	}

	if(ans)

	{

//		ans=num[1];

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

			if(num[i]&&num[i-1])

				ans=ans*ksm(num[i-1],num[i])%mod;

			else if(num[i]&&!num[i-1]) ans=0;

	}

	cout<<ans;

	return 0;

}

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

#include <map>

#include <cmath>



using namespace std;



#define mod 998244353

map<long long, long long> a;



long long quickpow(long long a, long long b){

    long long ans = 1;

    a = a % mod;

    while(b){

        if(b % 2) ans = (ans * a) % mod;

        a = (a * a) % mod;

        b >>= 1;

    }

    return ans;

}





int main() {

    long long n, t, flag = 1, maxn = 0;

    long long ans = 1;

    cin >> n;

    for (long long i = 0; i < n; i++) {

        cin >> t;

        a[t]++;

        maxn = max(maxn, t);

        if((i == 0 and t != 0) or (i != 0 and t == 0)) flag = 0;

    }

    if (flag) {

        for (long long i = 1; i <= maxn; i++) {

            ans = (ans % mod * quickpow(a[i - 1], a[i]) % mod) % mod;

        }

        cout << ans % mod << endl;

    } else cout << 0 << endl;

    return 0;

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

using namespace std;

typedef long long ll;

const ll mod=998244353;

ll ksm(ll a,ll b)

{

	ll ans=1;

	while(b)

	{

		if(b&1) ans=ans*a%mod;

		b/=2;

		a=a*a%mod;

	}

	return ans;

}

int main()

{

	ll n,x,ans=1,s[100100],num[100100];

	memset(num,0,sizeof num);

	cin>>n;

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

	{

		cin>>x;

		if(!i&&x) ans=0;

		else if(i&&!x) ans=0;

		num[x]++;

	}

	if(ans)

	{

//		ans=num[1];

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

			if(num[i]&&num[i-1])

				ans=ans*ksm(num[i-1],num[i])%mod;

			else if(num[i]&&!num[i-1]) ans=0;

	}

	cout<<ans;

	return 0;

}

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

using namespace std;

typedef long long ll;

const ll mod=998244353;

ll aa[123456];



ll ksm(ll a,ll b)

{

	ll res=1;

	while(b)

	{

		if(b&1) res=res*a%mod;

		a=a*a%mod;

		b>>=1;

	}

	return res%mod;

}

int main()

{

	int n,x;int maxx=0;

	ll count=1;

	cin>>n;

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

	{

		cin>>x;

		if(i==1&&x!=0) count=0;

		aa[x]++;

		maxx=max(x,maxx); 

	}	

	for(int i=maxx;i>1;i--)

	{

		if(aa[i]==0) count=0;

		count=count*ksm(aa[i-1],aa[i])%mod;

	}

	if(aa[0]>1) count=0;

	cout<<count<<endl;

	return 0;

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

using namespace std;

typedef long long ll;

const ll mod=998244353;

ll ksm(ll a,ll b)

{

	ll ans=1;

	while(b)

	{

		if(b&1) ans=ans*a%mod;

		b/=2;

		a=a*a%mod;

	}

	return ans;

}

int main()

{

	ll n,x,ans=1,s[100100],num[100100];

	memset(num,0,sizeof num);

	cin>>n;

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

	{

		cin>>x;

		if(!i&&x) ans=0;

		else if(i&&!x) ans=0;

		num[x]++;

	}

	if(ans)

	{

//		ans=num[1];

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

			if(num[i]&&num[i-1])

				ans=ans*ksm(num[i-1],num[i])%mod;

			else if(num[i]&&!num[i-1]) ans=0;

	}

	cout<<ans;

	return 0;

}

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

#define ll long long

using namespace std;



const ll mod = 998244353;



int dis[100000 + 10];



ll ksm(ll a, ll b)

{

	ll ans = 1;

	while( b )

	{

		if(b & 1) ans = ans * a % mod;

		b >>= 1;

		a = a * a % mod;

	}

	return ans;

}



int main()

{

	ll n;

	cin>>n;

	ll x;

	ll maxn=0;

	dis[0]=1;

	cin>>x;

	ll flag=0;

	if(x != 0)

	{

		flag = 1;

	}

//	printf("YES");

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

	{

		cin>>x;

		if(x == 0) flag = 1;

		maxn=max(maxn, x);

		dis[x]++;

	}

//	printf("NO");	

//	cout<<maxn<<endl;

	if(flag)

	{

		printf("0");

	}

	else

	{

		ll ans=1;

		for(ll i=1; i <= maxn; i++)

		{

			if(dis[i] == 0)

			{

				printf("0");

				return 0;

			}

			ans=ans*ksm(dis[i-1], dis[i])%mod;

		}

		cout<<ans;

	}	

//	printf("YEs");

	return 0;

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

using namespace std;

typedef long long ll;

const ll mod=998244353;

ll ksm(ll a,ll b)

{

	ll ans=1;

	while(b)

	{

		if(b&1) ans=ans*a%mod;

		b/=2;

		a=a*a%mod;

	}

	return ans;

}

int main()

{

	ll n,x,ans=1,s[100100],num[100100];

	memset(num,0,sizeof num);

	cin>>n;

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

	{

		cin>>x;

		if(!i&&x) ans=0;

		else if(i&&!x) ans=0;

		num[x]++;

	}

	if(ans)

	{

//		ans=num[1];

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

			if(num[i]&&num[i-1])

				ans=ans*ksm(num[i-1],num[i])%mod;

			else if(num[i]&&!num[i-1]) ans=0;

	}

	cout<<ans;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.807237983909631x):
#pragma GCC optimize(2) 

#include<iostream>

 

using namespace std;

const int mod=998244353;

long long a[100010];

long long n,x;

long long ksm(long long a,long long b){

	long long res=1;

	while(b){

		if(b&1){

			res*=a;

			res%=mod;

		}

		a*=a;

		a%=mod;

		b>>=1;

	}

	return res;

}

 

int main(){

	//scanf("%lld",&n);

	cin>>n;

	int flag=0;

//	scanf("%lld",&x);

	cin>>x;

	int ans=x;

	if(x!=0) flag=1;

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

//		scanf("%lld",&x);

		cin>>x;

		a[x]++;

		if(x==0) flag=1;

		if(x>ans){

			ans=x;

		}

	}

	if(flag){

	//	printf("0\n");

		cout<<0<<"\n";

	}

	else{

	long long sum=1;

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

			if(a[i]==0){

				flag=1;

				break;

			}

			sum*=ksm(a[i],a[i+1]);

			sum%=mod;

		}

		if(flag) cout<<0<<"\n";//printf("0\n");

		else  cout<<sum<<"\n";//printf("%lld\n",sum);

	}

	return 0;

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

using namespace std;

typedef long long ll;

const ll mod=998244353;

ll ksm(ll a,ll b)

{

	ll ans=1;

	while(b)

	{

		if(b&1) ans=ans*a%mod;

		b/=2;

		a=a*a%mod;

	}

	return ans;

}

int main()

{

	ll n,x,ans=1,s[100100],num[100100];

	memset(num,0,sizeof num);

	cin>>n;

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

	{

		cin>>x;

		if(!i&&x) ans=0;

		else if(i&&!x) ans=0;

		num[x]++;

	}

	if(ans)

	{

//		ans=num[1];

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

			if(num[i]&&num[i-1])

				ans=ans*ksm(num[i-1],num[i])%mod;

			else if(num[i]&&!num[i-1]) ans=0;

	}

	cout<<ans;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2791993151360819x):
/**

 * code generated by JHelper

 * More info: https://github.com/AlexeyDmitriev/JHelper

 * @author YahiaAshraf74

 */



#include <iostream>

#include <algorithm>

#include <cmath>

#include <vector>

#include <set>

#include <map>

#include <unordered_set>

#include <unordered_map>

#include <queue>

#include <stack>

#include <complex>

#include <string>

#include <bitset>

#include <stdio.h>

#include <string.h>

#include <fstream>

#include <iomanip>

#include <assert.h>



using namespace std;

#define el  '\n'

#define ll long long

#define clr(a, b)memset(a,b,sizeof(a))

#define sz(a) (int)(a).size()

const long long N = 1e5 + 74, OO = 0x3f3f3f3f, MOD = 998244353;



int f[N], a[N];



long long power(long long b, long long p, long long MOD = 998244353) {

    long long res = 1;

    b %= MOD;

    for (; p; p >>= 1LL) {

        if (p & 1)res = (res * b) % MOD;

        b = (b * b) % MOD;

    }

    return res % MOD;

}



class BCountingOfTrees {

public:

    void solve(istream &cin, ostream &cout) {

        int n;

        cin >> n;

        int mx = 0;

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

            cin >> a[i];

            f[a[i]]++;

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

        }

        if (f[0] != 1 || a[0] != 0)

            return (void) (cout << 0 << el);

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

            if (!f[i]) {

                cout << "0\n";

                return;

            }

        int ans = 1;

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

            ans = (ans * power(f[i - 1], f[i])) % MOD;



        cout << ans << el;

        clr(f, 0);

    }

};



int main() {

    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    BCountingOfTrees solver;

    std::istream &in(std::cin);

    std::ostream &out(std::cout);

    solver.solve(in, out);

    return 0;

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

#define ll long long

#define double long double

#define rep(i,n) for(int i=0;i<(n);i++)

#define REP(i,n) for(int i=1;i<=(n);i++)

#define mod (ll)(1e9+7)

#define inf (ll)(3e18+7)

#define pi (double) acos(-1)

#define P pair<int,int>

#define PiP pair<int,pair<int,int>>

#define all(x) x.begin(),x.end()

using namespace std;

 

int main() {

    ll n, ans=1, mo = 998244353;

    cin >> n;

    vector<ll> d(n), num(100004, 0);

    rep(i, n){

        cin >> d.at(i);

        num[d.at(i)]++;

    }

    if(d.at(0) != 0)ans=0;

    sort(all(d));

    if(num[0] != 1)ans=0;

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

        if(d.at(i) - d.at(i-1) > 1)ans=0;

        ans = ans*num[d.at(i)-1]%mo;

    }

    cout << ans << endl;

}


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

#define ll long long

#define double long double

#define rep(i,n) for(int i=0;i<(n);i++)

#define REP(i,n) for(int i=1;i<=(n);i++)

#define mod (ll)(1e9+7)

#define inf (ll)(3e18+7)

#define pi (double) acos(-1)

#define P pair<int,int>

#define PiP pair<int,pair<int,int>>

#define all(x) x.begin(),x.end()

using namespace std;

 

int main() {

    ll n, now=-1, ans=1, mo = 998244353, bf=1, ne=0;

    cin >> n;

    vector<ll> d(n);

    rep(i, n)cin >> d.at(i);

    if(d.at(0) != 0)ans=0;

    sort(all(d));

    rep(i, n){

        if(d.at(i) == now)ne++;

        else{

            if(now+1 != d.at(i)){

                ans = 0;

                break;        

            }

            else{

                now++;

                bf=ne;

                ne=1;

            }

        }

        if(i){

            ans *= bf;

            ans %= mo;

        }

    }

    cout << ans;

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

#include <string>

#include <stdio.h>

#include <vector>

#include <algorithm>

#include<math.h>

#include<string.h>

#include<queue>



using namespace std;



#define M  100000+100

#define mod 998244353

typedef long long ll;



ll a[M];

ll b[M];



ll pow_mod(ll a, ll n)

{

    ll ans = 1;

    a=a%mod;

    while(n){

        if(n&1){

            ans = (ans * a) % mod;

        }

        a = (a * a) % mod;

        n >>= 1;

    }

    return ans;

}

int main()

{



    ll n;

    cin>>n;

    memset(b,0,sizeof(b));

    ll c,sum=1;

    ll maxx=-1;

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

    {

        cin>>a[i];

        b[a[i]]++;

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

    }

    if(a[1]||b[0]>1) cout<<"0";

    else

    {

        sum=1;

        for(int i=2; i<=maxx; i++)

        {

            if(!b[i-1])

            {

                sum=0;

                break;

            }

            else

            {

                ll k=pow_mod(b[i-1],b[i]);

                sum=(sum*k)%mod;

            }

        }

        cout<<sum;

    }

    return 0;

}


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

#include<string.h>

#include<iostream>

#include<algorithm>

#include<string.h>

#include<math.h>

#define ll long long

using namespace std;

int main()

{

    int n;

    scanf("%d",&n);

    ll a[100005],i;

    ll b[100005];

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

        scanf("%lld",&a[i]),b[i]=0;

    if(a[0]!=0)

            printf("0\n");

    else

    {

        ll ans=1;

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

            b[a[i]]++;

         if(b[0]>1) cout << "0" ; 

        else{

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

        {

            ans*=b[a[i]-1];

            ans%=998244353;

        }

            

        printf("%lld\n",ans);}

    }

    return 0;

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

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)

#define MOD 998244353



long long pow_mod(long long x, long long y){



    long long tmp = 1;

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

        tmp *= x;

        tmp %= MOD;

    }

    return tmp;

}



int main()

{

    long long n;

    cin >> n;

    vector<int> d(n);

    int v[100000] = {0};

    int max_n = 0;

    rep(i, n){

        cin >> d[i];

        max_n = max(max_n, d[i]);

        v[d[i]]++;

    }



    if(d[0] != 0 || v[0] != 1){

        cout << 0;

        return 0;

    }



    long long hen = v[1], youso;

    long long ans = 1;

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

        youso = v[i];

        if(v[i] == 0){

            cout << 0;

            return 0;

        }

        ans *= pow_mod(hen, youso);

        ans %= MOD;

        hen = youso;

    }



    cout << ans;



    return 0;

}


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

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)

#define MOD 998244353



long long pow_mod(long long x, long long y){



    long long res = x;

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

        res *= x;

        res %= MOD;

    }

    return res;

}



int main()

{

    long long n;

    cin >> n;

    vector<int> v(n, 0);

    int max_n = 0;

    rep(i, n){

        int d;

        cin >> d;

        if(i == 0 && d != 0){

            cout << 0;

            return 0;

        }

        max_n = max(max_n, d);

        v[d]++;

    }



    if(v[0] != 1){

        cout << 0;

        return 0;

    }



    long long pre = v[1], now;

    long long ans = 1;

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

        now = v[i];

        if(v[i] == 0){

            cout << 0;

            return 0;

        }

        ans *= pow_mod(pre, now);

        ans %= MOD;

        pre = now;

    }



    cout << ans;



    return 0;

}