#include <bits/stdc++.h>
inline int read() {
  char c = getchar();
  int x = 0, ft = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') ft = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  return x * ft;
}
const int mod = 998244353, N = 2e6 + 5;
int k, m, fac[N], inv[N], a[N], cnt[N], cur, ans;
inline int combn(int n, int m) {
  return (m < 0 || m > n) ? 0 : 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
  k = read();
  m = 2e6;
  fac[0] = inv[0] = inv[1] = 1;
  for (int i = 1; i <= m; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
  for (int i = 2; i <= m; ++i)
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
  for (int i = 1; i <= m; ++i) inv[i] = 1ll * inv[i - 1] * inv[i] % mod;
  for (int i = 1; i <= k; ++i) a[i] = read();
  std::sort(a + 1, a + 1 + k);
  for (int s = 0, j = 1; s <= a[k]; ++s) {
    while (a[j] < s) ++cnt[a[j++] % k];
    cur += cnt[(s - 1 + k) % k];
    if (cur > s) break;
    ans = (ans + combn(s - cur + k - 1, k - 1)) % mod;
    ans = (ans + mod - combn(s - cur + j - 2, k - 1)) % mod;
  }
  printf("%d\n", ans);
  return 0;
}
