#include <bits/stdc++.h>
using namespace std;
const int Mod = 998244353;
int add(int a, int b) { return a + b >= Mod ? a + b - Mod : a + b; }
int dec(int a, int b) { return a - b < 0 ? a - b + Mod : a - b; }
int mul(int a, int b) { return 1ll * a * b % Mod; }
void Add(int &a, int b) { a = add(a, b); }
void Dec(int &a, int b) { a = dec(a, b); }
void Mul(int &a, int b) { a = mul(a, b); }
int ksm(int a, int b) {
  int ans = 1;
  for (; b; b >>= 1, Mul(a, a))
    if (b & 1) Mul(ans, a);
  return ans;
}
const int N = 1e6 + 50;
int n, a[N], b[N], fc[N + N], ifc[N + N];
int C(int n, int m) {
  if (n < 0 || m < 0 || n < m) return 0;
  return mul(fc[n], mul(ifc[n - m], ifc[m]));
}
int F(int a, int b) {
  if (a < 0) return 0;
  return C(b + a - 1, a);
}
void fc_init(int n) {
  fc[0] = ifc[0] = 1;
  for (int i = 1; i <= n; i++) fc[i] = mul(fc[i - 1], i);
  ifc[n] = ksm(fc[n], Mod - 2);
  for (int i = n - 1; i; i--) ifc[i] = mul(ifc[i + 1], i + 1);
}
int main() {
  cin >> n;
  fc_init(2e6);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  int lm = 1e6 + n;
  for (int i = 1; i <= n; i++)
    if (a[i] + 1 < i) {
      lm = i - 1;
      break;
    }
  int ct = 0, ans = 0;
  for (int i = 0, l = 0; i <= lm; i++) {
    while (l < n && a[l + 1] < i) ++l, ++b[(a[l] + 1) % n];
    ct += b[i % n];
    if (ct > i) continue;
    Add(ans, F(i - ct, n));
    Dec(ans, F(i - ct - (n - l), n));
  }
  cout << ans;
  return 0;
}
