#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

uint64_t EuclidMod(uint64_t v, uint64_t m){
  assert(v>=0);
  assert(m>0);
  // if(0 <= v && v < m){
  //   return v;
  // }else if(-m <= v && v < 0){
  //   return v + m;
  // }else{
  //   uint64_t result = v % m;
  //   if(result < 0){
  //     result += m;
  //   }
  //   return result;
  // }
  return v%m;
}

uint64_t ModInv(uint64_t a, uint64_t m){
  uint64_t b = m, u = 1, v = 0;
  while(b){
    uint64_t t = a / b;
    a -= t * b;
    std::swap(a, b);
    u -= t * v;
    std::swap(u, v);
  }
  EuclidMod(u, m);
  return u;
}

// return base^exponent (MOD. mod).
uint64_t RepeatedPowMod(uint64_t base, uint64_t exponent, uint64_t mod) {
  if (exponent == 0)
    return 1;
  else if (exponent % 2 == 0) {
    uint64_t root = RepeatedPowMod(base, exponent / 2, mod);
    return (root * root) % mod;
  } else {
    return ((base%mod) * RepeatedPowMod(base, exponent - 1, mod)) % mod;
  }
}

template<uint64_t mod>
class ModInt{
  uint64_t value_;

public:
  explicit ModInt(const uint64_t x = 0): value_(x % mod){
  };

  ModInt& operator=(const ModInt& another){
    value_=another.value_;
    return *this;
  }

  ModInt& operator^=(const ModInt& another){
    value_=RepeatedPowMod(value_,another.value_,mod);
    return *this;
  }

  ModInt& operator+=(const ModInt& another){
    value_ += another.value_;
    value_ = EuclidMod(value_, mod);
    return *this;
  }

  ModInt& operator-=(const ModInt& another){
    value_ -= another.value_;
    value_ = EuclidMod(value_, mod);
    return *this;
  }

  ModInt& operator*=(const ModInt& another){
    value_ *= another.value_;
    value_ = EuclidMod(value_, mod);
    return *this;
  }

  ModInt& operator/=(const ModInt& another){
    value_ = value_ * ModInv(another.value_, mod);
    value_ = EuclidMod(value_, mod);
    return *this;
  }

  ModInt& operator++(){
    value_ += 1;
    value_=EuclidMod(value_,mod);
    return *this;
  }

  ModInt operator++(int){
    ModInt tmp = *this;
    this->value_+=1;
    this->value_=EuclidMod(this->value_,mod);
    return tmp;
  }

  ModInt& operator--(){
    value_ -= 1;
    value_=EuclidMod(value_,mod);
    return *this;
  }

  ModInt operator--(int){
    ModInt tmp=*this;
    this->value_-=1;
    this->value_=EuclidMod(this->value_,mod);
    return tmp;
  }



  uint64_t GetValue() const{
    return value_;
  }

};

template<uint64_t mod>
ModInt<mod>
operator+(const ModInt<mod>& left, const ModInt<mod>& right){
  return ModInt<mod>(left) += right;
}

template<uint64_t mod>
ModInt<mod>
operator-(const ModInt<mod>& left, const ModInt<mod>& right){
  return ModInt<mod>(left) -= right;
}

template<uint64_t mod>
ModInt<mod>
operator/(const ModInt<mod>& left, const ModInt<mod>& right){
  return ModInt<mod>(left) /= right;
}

template<uint64_t mod>
ModInt<mod>
operator*(const ModInt<mod>& left, const ModInt<mod>& right){
  return ModInt<mod>(left) *= right;
}

template<uint64_t mod>
ModInt<mod>
operator^(const ModInt<mod>& left, const ModInt<mod>& right){
  return ModInt<mod>(left) ^= right;
}

template<uint64_t mod>
std::ostream& operator<<(std::ostream& stream, const ModInt<mod>& mod_int){
  stream << mod_int.GetValue();
  return stream;
}



using std::cerr;
using std::cin;
using std::cout;
using std::endl;

const uint64_t MOD=998244353;

int main(void){
  cout << std::fixed << std::setprecision(16);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  uint64_t n;
  cin>>n;
  std::vector<uint64_t> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  if(a[0]!=0){
    cout<<0<<endl;
    return 0;
  }
  uint64_t max_a=0;

  std::vector<uint64_t> count(100001);
  for(int i=0;i<=100000;i++){
    count[i]=0;
  }
  for(auto v:a){
    count[v]++;
    max_a=std::max(max_a,v);
  }
  if(count[0]!=1){
    cout<<0<<endl;
    return 0;
  }
  if(n==1){
    cout<<1<<endl;
    return 0;
  }

  uint64_t result(1);
  for(uint64_t i=1;i<=max_a;i++){
    if(count[i]==0){
      cout<<0<<endl;
      return 0;
    }
    for(int j=0;j<count[i];j++){
      result*=count[i-1];
      result%=MOD;
    }

    assert(result>=0);

  }

  cout<<result%MOD<<endl;






  return 0;
}


Measured memory_bytes: 1920