#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
inline int add(int a, int b) {
  if ((a += b) >= mod) a -= mod;
  return a;
}
inline int dec(int a, int b) {
  if ((a -= b) < 0) a += mod;
  return a;
}
inline int mult(int a, int b) {
  long long t = 1ll * a * b;
  if (t >= mod) t %= mod;
  return t;
}
inline int power(int a, int b) {
  int out = 1;
  while (b) {
    if (b & 1) out = mult(out, a);
    a = mult(a, a);
    b >>= 1;
  }
  return out;
}
int fac[1100010], ifac[1100010], a[100010], cnt[1000010], mx, lft[1000010];
inline int C(int a, int b) {
  if (a < b) return 0;
  return mult(fac[a], mult(ifac[b], ifac[a - b]));
}
int k;
int main() {
  fac[0] = 1;
  for (int i = 1; i <= 1100000; i++) fac[i] = mult(fac[i - 1], i);
  ifac[1100000] = power(fac[1100000], mod - 2);
  for (int i = 1099999; i >= 0; i--) ifac[i] = mult(ifac[i + 1], i + 1);
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
    mx = max(mx, a[i]);
  }
  for (int i = 1; i <= k; i++) {
    for (int j = a[i] + 1; j <= mx; j += k) lft[j]++;
  }
  int ans = 1, count = k, empt = 0;
  for (int s = 1; s <= mx; s++) {
    empt++;
    count -= cnt[s - 1];
    if (empt < lft[s]) break;
    empt -= lft[s];
    ans = add(ans, C(empt + k - 1, k - 1));
    ans = dec(ans, C(empt - count + k - 1, k - 1));
  }
  printf("%d\n", ans);
  return 0;
}
