// Original C++ solution (slower):
/*

    Author:zeke

    

    pass System Test!

    GET AC!!

*/

#include <iostream>

#include <queue>

#include <vector>

#include <iostream>

#include <vector>

#include <string>

#include <cassert>

#include <algorithm>

#include <functional>

#include <cmath>

#include <queue>

#include <set>

#include <stack>

#include <deque>

#include <map>

#include <iomanip>

#include <utility>

#include <stack>

using ll = long long;

using ld = long double;

using namespace std;

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

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

#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))

#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))

#define Mp(a,b) make_pair((a),(b))

#define F first

#define S second

#define CIN(s) int (s);cin>>(s);

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef pair<ll, ll> P;

typedef vector<ll> V;

typedef vector<V> VV;

typedef vector<P> VP;

ll MOD = 998244353;

ll INF =1e18;



int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n;

    cin>>n;

    V vec(n);

    rep(i,n)cin>>vec[i];

    if(vec[0]!=0){

        cout<<0<<endl;

        return 0;

    }

    V reg(1e5+1);

    rep(i,n)reg[vec[i]]++;

    ll res=1;

    ll prev=1;

    sort(all(vec));

    rep3(i,1,n){

        if(vec[i-1]!=vec[i]&&vec[i-1]!=vec[i]-1){

            cout<<0<<endl;

            return 0;

        }

        if(vec[i]==0){

            cout<<0<<endl;

            return 0;

        }

    }

    rep3(i,1,n+1){

      //  cout<<res<<endl;

        if(reg[i]==0)continue;

        

        rep(j,reg[i]){

            res*=prev;

            res%=MOD;

        }

        prev=reg[i];

    }

    cout<<res<<endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int, int> P;

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

#define rall(x) (x).rbegin(), (x).rend()

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

#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)

#define Rep(i, r, n) for (ll i = r; i < n; i++)

#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)

#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;

#define fs first

#define sc second

#define int long long

#define pb push_back

const int dx[] = {0, -1, 0, 1};

const int dy[] = {1, 0, -1, 0};

//const int MOD = (1000000007);

const int MOD = (998244353);

//const int INF = (1 << 30)-1;

const int INF = (1LL << 60) - 1;

const double EPS = (1 >> 30);



ll mod_pow(ll x, ll y)

{

    ll res = 1;

    while (y > 0)

    {

        if (y & 1)

        {

            res = res * x % MOD;

        }

        x = x * x % MOD;

        y >>= 1;

    }

    return res;

}



signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout << fixed << setprecision(10);

    //---------------------------------------------



    int n;

    cin >> n;

    vector<int> d(n);

    rep(i, n) cin >> d[i];

	if(d[0]!=0){

      cout<<0<<endl;

      return 0;

    }

    sort(all(d));

    vector<P> a(n);

    int c = 0;

    a[0]=make_pair(d[0],1);

    for (int i = 1; i < n; i++) // 距離ｘがそれぞれいくつあるか

    {

        if (d[i - 1] == d[i])

        {

            a[c].sc++;

        }

        else

        {

            c++;

            a[c].fs = d[i];

            a[c].sc++;

        }

    }

    c++;



    int dame = 0;

    rep(i, c) //　距離がれんぞくになってないとだめ

    {

        if (a[i].fs != i)

        {

            dame++;

        }

    }



    ll ans = 1;

    Rep(i, 1, c) // 距離ｘは距離ｘ－１に繋ぐことになる

    {

        ans *= mod_pow(a[i - 1].sc, a[i].sc);

        ans %= MOD;

    }



    if (n == 1) // n==1の処理

    {

        if (d[0] == 0)

        {

            cout << 1 << endl;

        }

        else

        {

            cout << 0 << endl;

        }

    }

    else if (dame > 0) // 距離が飛んでいてつくれない

    {

        cout << 0 << endl;

    }

    else

    {

        if(d[1]!=1){ // 1は必ずいる

            cout<<0<<endl;

        }

        else{

            cout<<ans<<endl;

        }

    }

}


// Fastest known solution for this problem: