#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <sstream>
#include <climits>
#include <fstream>
#include <cmath>

using namespace std;

/// ********* debug template by Bidhan Roy *********

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const unordered_set< T > &v ) {
    os << "[";
    typename unordered_set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << ": " << it -> second ;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const unordered_map< F, S > &v ) {
    os << "[";
    typename unordered_map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << ": " << it -> second ;
    } 
    return os << "]";
}

#define debug(x) cerr << #x << " = " << x << endl;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<bool> VB;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<LL> VLL;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<VB> VVB;
typedef vector<VI> VVI;
typedef vector<VC> VVC;
typedef vector<VLL> VVLL;
typedef vector<VD> VVD;
typedef vector<VS> VVS;

// TEMPLATE DEFINITIONS END

LL MOD = 998244353;

int n;
VI a;

void read_input(){
    cin >> n; // 1 <= n <= 10^5
    a.resize(n);
    for(int i=0;i<n;i++) cin >> a[i];
}

LL perm(LL n, LL k){
    LL res = 1;
    for(int i=0;i<k;i++){
        res = (res * n) % MOD;
    }
    return res;
}

void solve(){
    sort(a.begin() + 1, a.end());

    LL sol = 0;

    if(n == 1){
        if(a[0] == 0) sol = 1; else sol = 0;
        cout << sol << "\n";
        return;
    }

    if(a[0] != 0 || (a[0] == 0 && a[1] == 0)){
        cout << sol << "\n";
        return;
    }

    debug(a);
    int curr = 1, cnt = 0, prev_cnt = 1;
    sol = 1;
    for(int i=1;i<n;i++){
        if(a[i] != curr){
            cout << 0 << "\n";
            return;
        }

        cnt++;

        if(i + 1 >= n || a[i + 1] != curr){
            sol = (sol * perm(prev_cnt, cnt)) % MOD;

            // VI deb = {i, curr, prev_cnt, cnt, (int)sol};
            // debug(deb);
            // cout << "########################\n";

            prev_cnt = cnt;
            cnt = 0;
            curr++;
        }
    }

    cout << sol << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    read_input();
    solve();
    return 0;
}


Measured memory_bytes: 640