#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000 + 17, mod = 998244353;
int pw(int a, int b) {
  if (b == 0) return 1;
  int res = 1;
  while (b) {
    if (b & 1) res = (1LL * a * res) % mod;
    a = (1LL * a * a) % mod;
    b >>= 1;
  }
  return res;
}
int n, a[MAXN], c[MAXN], ans = 1;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  int now = 0, cnt = 1;
  if (a[1] != 0) return cout << 0 << endl, 0;
  for (int i = 1; i <= n; i++)
    if (a[i] == cnt)
      now++;
    else {
      if (!now) return cout << 0 << endl, 0;
      c[cnt] = now;
      now = 1;
      cnt++;
      if (a[i] != cnt) return cout << 0 << endl, 0;
    }
  if (c[0] != 1) return cout << 0 << endl, 0;
  c[cnt] = now;
  for (int i = 1; i <= cnt + 10; i++)
    ans = (1LL * pw(c[i - 1], c[i]) * ans) % mod;
  cout << ans << endl;
  return 0;
}
