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

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<iostream>

#include<vector>

#include<set>

#include<map>

#include<numeric>

#include<deque>

using namespace std;

typedef long long ll;

typedef pair<int,int> PII;

const int INF=1e9+7;

const int MOD=998244353;

const int N = 1e6 + 5;

const ll inv2=499122177;

const double pi=acos(-1);

ll k[100005],s[100005];

ll qpmod(ll a,ll n)

{

	ll ret=1;

	while(n)

	{

	   	if(n&1)

	      	ret=(ret*a)%MOD;

	   	a=(a*a)%MOD;

		n>>=1;

	}

	return ret;

}

int main()

{

	ll n;

	int flag=1;

	scanf("%lld",&n);

	memset(k,0,sizeof(k));

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

	{

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

		if(s[i]==0&&i!=0)

			flag=0;

		if(s[0]!=0)

			flag=0;

		k[s[i]]++;

	}

	if(flag==0)

		printf("0\n");

	else

	{

		ll ans=1;

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

		{

			ans=(ans*qpmod(k[i],k[i+1]))%MOD;

		}

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

	}

    return 0;

}




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

using namespace std;

using LL = long long;

using ULL = unsigned long long;

using VI = vector<int>;

using VL = vector<LL>;

using PII = pair<int, int>;

using PLL = pair<LL, LL>;



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

#define ALL(a) a.begin(), a.end()

#define MP make_pair

#define PB push_back

#define EB emplace_back

#define F first

#define S second

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

#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)

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



void dout() { cerr << endl; }



template <typename Head, typename... Tail>

void dout(Head H, Tail... T) {

    cerr << H << ' ';

    dout(T...);

}



const int mod = 998244353;



int mul(int a, int b)

{

    return (LL)a * b % mod;

}



int binpow(int a, int n)

{

    int res = 1;

    while (n > 0)

    {

        if (n & 1)

            res = mul(res, a);

        a = mul(a, a);

        n >>= 1;

    }

    return res;

}



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int n;

    cin >> n;

    VI d(n);

    FOR(i, 0, n)

        cin >> d[i];

    VI cnt(n);

    int depth = 0;

    for (auto x : d)

    {

        cnt[x]++;

        depth = max(depth, x);

    }

    LL ans = (cnt[0] == 1 && d[0] == 0);

    FOR(i, 1, depth + 1)

    {

        ans = mul(ans, binpow(cnt[i - 1], cnt[i]));

    }

    cout << ans << "\n";

    return 0;

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

#include<string.h>

#include<iostream>

#include<algorithm>

#include<string.h>

#include<math.h>

#define ll long long

using namespace std;

const  ll mod=998244353;

ll qp(ll a,ll k)

{

	ll ans=1;

	a%=mod;

	while(k)

	{

		if(k%2)

			ans=(ans*a)%mod;

		a=(a*a)%mod;

		k/=2;

	}

	return ans;

}

int main()

{

    int n;

    scanf("%d",&n);

    int a[100005],i;

    int b[100005],flag=1;

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

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

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

    if(a[0]!=0)

        printf("0\n");

    else

    {

        ll ans=1;

        int t;

        for(i=n-1;b[i]==0;i--);

        t=i;

        if(b[0]==1)

        {

            for(i=2; i<=t; i++)

            {

                if(b[i]==0)

                {

                    flag=0;

                    break;

                }

                ans=(ans*(ll)qp(b[i-1],b[i]))%mod;

            }

            if(flag==1)

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

            else

            	printf("0\n");

        }

        else

            printf("0\n");

    }



    return 0;

}


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

#include<string.h>

#include<iostream>

#include<algorithm>

#include<string.h>

#include<math.h>

#define ll long long

using namespace std;

ll b[1000005];

int main()

{

    int n;

    scanf("%d",&n);

    

    ll a[100005],i;

    

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

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

    if(n>=1e5)

        a[-2]=0;

    if(a[0]!=0)

            printf("0\n");

    else

    {

        ll ans=1;

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

            b[a[i]]++;

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

        {

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

            ans%=998244353;

        }



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

    }

    return 0;

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

#include<string.h>

#include<iostream>

#include<algorithm>

#include<string.h>

#include<math.h>

#define ll long long

using namespace std;

ll b[1000005];

int main()

{

    int n;

    scanf("%d",&n);

    

    ll a[100005],i;

    

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

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

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

    if(n>=1e5)

        a[-2]=0;

    if(a[0]!=0)

            printf("0\n");

    else

    {

        ll ans=1;

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

            b[a[i]]++;

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

        {

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

            ans%=998244353;

        }



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

    }

    return 0;

}


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

#include<string.h>

#include<iostream>

#include<algorithm>

#include<string.h>

#include<math.h>

#define ll long long

using namespace std;

ll b[100005];

int main()

{

    int n;

    scanf("%d",&n);

    

    ll a[100005],i;

    

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

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

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

    if(n>=1e5)

        a[-2]=0;

    if(a[0]!=0)

            printf("0\n");

    else

    {

        ll ans=1;

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

            b[a[i]]++;

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

        {

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

            ans%=998244353;

        }



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

    }

    return 0;

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

#include<string.h>

#include<iostream>

#include<algorithm>

#include<string.h>

#include<math.h>

#define ll long long

using namespace std;

ll b[1000005];

int main()

{

    int n;

    scanf("%d",&n);

    

    ll a[100005],i;

    

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

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

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

    if(n>=1e5)

        a[-2]=0;

    if(a[0]!=0)

            printf("0\n");

    else

    {

        ll ans=1;

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

            b[a[i]]++;

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

        {

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

            ans%=998244353;

        }



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

    }

    return 0;

}


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

#include<string.h>

#include<iostream>

#include<algorithm>

#include<string.h>

#include<math.h>

#define ll long long

using namespace std;

ll b[100005];

int main()

{

    int n;

    scanf("%d",&n);

    

    ll a[100005],i;

    

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

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

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

        b[i]=0;

    if(n>=1e5)

        a[-2]=0;

    if(a[0]!=0)

            printf("0\n");

    else

    {

        ll ans=1;

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

            b[a[i]]++;

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

        {

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

            ans%=998244353;

        }



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

    }

    return 0;

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

#include<string.h>

#include<iostream>

#include<algorithm>

#include<string.h>

#include<math.h>

#define ll long long

using namespace std;

ll b[1000005];

int main()

{

    int n;

    scanf("%d",&n);

    

    ll a[100005],i;

    

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

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

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

    if(n>=1e5)

        a[-2]=0;

    if(a[0]!=0)

            printf("0\n");

    else

    {

        ll ans=1;

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

            b[a[i]]++;

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

        {

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

            ans%=998244353;

        }



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

    }

    return 0;

}


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

#include<string.h>

#include<iostream>

#include<algorithm>

#include<string.h>

#include<math.h>

#define ll long long

using namespace std;

ll b[100005];

int main()

{

    int n;

    scanf("%d",&n);

    

    ll a[100005],i;

    

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

    {

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

        if(a[i]>=1e5)

            a[-2]=0;

    }

        

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

        b[i]=0;

    

    if(a[0]!=0)

            printf("0\n");

    else

    {

        ll ans=1;

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

            b[a[i]]++;

        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;

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.381894794580293x):
#include<iostream>

#include<map>

#include<cmath>



using namespace std;

const int N = 1e5+5;

typedef long long ll;

const ll mod = 998244353;

ll a[N];

map<ll,ll>ma;



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;

}



int main(){

	ll n;

	cin>>n;

	bool flag=0;

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

		cin>>a[i];

		ma[a[i]]++;

		if(i==1){

			if(a[i]!=0) flag=1;

		}

		else {

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

		}

	}

	if(ma[0]>1) flag=1;

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

		if(ma[i]>0&&ma[i-1]==0) flag=1;

//		if(ma[i]==0) break;

	}

	ll ans=1;

	if(flag) cout<<0<<endl;

	else {

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

		if(ma[i]&&ma[i-1]) ans=ans*ksm(ma[i-1],ma[i])%mod;

			else break;

		}

		cout<<ans%mod<<endl;

	}

	

	

	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.606115806291542x):
#include<iostream>

#include<map>

#include<cmath>



using namespace std;

const int N = 1e5+5;

typedef long long ll;

const ll mod = 998244353;

ll a[N];

map<ll,ll>ma;



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;

}



int main(){

	ll n;

	cin>>n;

	bool flag=0;

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

		cin>>a[i];

		ma[a[i]]++;

		if(i==1){

			if(a[i]!=0) flag=1;

		}

		else {

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

		}

	}

	if(ma[0]>1) flag=1;

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

		if(ma[i]>0&&ma[i-1]==0) flag=1;

//		if(ma[i]==0) break;

	}

	ll ans=1;

	if(flag) cout<<0<<endl;

	else {

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

		if(ma[i]&&ma[i-1]) ans=ans*ksm(ma[i-1],ma[i])%mod;

			else break;

		}

		cout<<ans%mod<<endl;

	}

	

	

	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: 1.4402251188294535x):
#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;

}
// 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.3934194956528518x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=1E5+7;

ll arr[N];

const int MOD=998244353;

ll ksm(ll x, ll y){

	ll res=1;

	while(y){

		if(y&1) res=res*x%MOD;

		x=x*x%MOD;

		y>>=1;

	}

	return res%MOD;

}



int main(){

	ll n;

	cin>>n;

	ll sum=1;

	ll x;

	ll s=0;

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

		cin>>x;

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

		arr[x]++;

		s=max(s,x);

	}

	for(int i=s;i>=0;i--){

		if(arr[i]==0) sum=0;

		if(i>1)	sum=sum*ksm(arr[i-1],arr[i])%MOD;

	}

	if(arr[0]>1) sum=0;

	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.627850243490216x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=1E5+7;

ll arr[N];

const int MOD=998244353;

ll ksm(ll x, ll y){

	ll res=1;

	while(y){

		if(y&1) res=res*x%MOD;

		x=x*x%MOD;

		y>>=1;

	}

	return res%MOD;

}



int main(){

	ll n;

	cin>>n;

	ll sum=1;

	ll x;

	ll s=0;

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

		cin>>x;

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

		arr[x]++;

		s=max(s,x);

	}

	for(int i=s;i>=0;i--){

		if(arr[i]==0) sum=0;

		if(i>1)	sum=sum*ksm(arr[i-1],arr[i])%MOD;

	}

	if(arr[0]>1) sum=0;

	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.8246107564253622x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=1E5+7;

ll arr[N];

const int MOD=998244353;

ll ksm(ll x, ll y){

	ll res=1;

	while(y){

		if(y&1) res=res*x%MOD;

		x=x*x%MOD;

		y>>=1;

	}

	return res%MOD;

}



int main(){

	ll n;

	cin>>n;

	ll sum=1;

	ll x;

	ll s=0;

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

		cin>>x;

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

		arr[x]++;

		s=max(s,x);

	}

	for(int i=s;i>=0;i--){

		if(arr[i]==0) sum=0;

		if(i>1)	sum=sum*ksm(arr[i-1],arr[i])%MOD;

	}

	if(arr[0]>1) sum=0;

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

	

	return 0;

}
// 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.39081297032605x):
#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)

			{

				flag = 1;

			}

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

		}

		if(flag) printf("0");

		else cout<<ans;

	}	

//	printf("YEs");

	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.622934596597038x):
#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)

			{

				flag = 1;

			}

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

		}

		if(flag) printf("0");

		else cout<<ans;

	}	

//	printf("YEs");

	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.8211976463296478x):
#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)

			{

				flag = 1;

			}

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

		}

		if(flag) printf("0");

		else cout<<ans;

	}	

//	printf("YEs");

	return 0;

}