#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 5;
const int mod = 998244353;
inline int gi() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum;
}
int fac[maxn], ifac[maxn];
int a[maxn], b[maxn], cnt[maxn];
int fpow(int x, int k) {
  int res = 1;
  while (k) {
    if (k & 1) res = (long long)res * x % mod;
    k >>= 1;
    x = (long long)x * x % mod;
  }
  return res;
}
int C(int x, int y) {
  if (y > x)
    return 0;
  else
    return 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
void init(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
  ifac[n] = fpow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--) ifac[i] = ifac[i + 1] * (i + 1ll) % mod;
}
int main() {
  int n, Max = 0;
  n = gi();
  for (int i = 1; i <= n; i++) b[(a[i] = gi()) + 1]++, Max = max(Max, a[i]);
  init(Max + n);
  for (int i = 1; i <= n; i++)
    for (int j = a[i] + 1; j <= Max; j += n) cnt[j]++;
  int ans = 1, empty = 0, lft = n;
  for (int i = 1; i <= Max; i++) {
    empty++, lft -= b[i];
    if (empty < cnt[i]) break;
    empty -= cnt[i];
    ans = (ans + C(empty + n - 1, n - 1)) % mod;
    if (empty >= lft) ans = (ans + mod - C(empty - lft + n - 1, n - 1)) % mod;
  }
  printf("%d\n", ans);
  return 0;
}
