#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
const long long MOD2 = (long long)998244353 * (long long)998244353;
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
int fac[1200035], inv[1200035];
void initfac(int n) {
  fac[0] = inv[0] = 1;
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    fac[i] = (long long)fac[i - 1] * i % 998244353;
    inv[i] = fastPow(fac[i], 998244353 - 2);
  }
}
int C(int n, int m) {
  if (n < m) return 0;
  return (long long)fac[n] * inv[m] % 998244353 * inv[n - m] % 998244353;
}
int a[1200035], ans, b[1200035];
void cal(int t) {
  for (int x = 0, j = 1; x <= t; x++) {
    while (j <= n && a[j] < x) j++;
    int num = j - 1;
    addmod(ans, C(x - num + n - 1, n - 1));
  }
  printf("%d\n", ans);
  exit(0);
}
void fmain(int tid) {
  scanf("%d", &n);
  initfac(1200035 - 1);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", a + i);
  sort(a + 1, a + 1 + n);
  for (int i = 1; i < n; i++) {
    if (a[i + 1] < i) {
      cal(i - 1);
    }
  }
  int all = 0, ps = 0;
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    all += a[i];
    b[i] = a[i] % n;
    ps += b[i];
  }
  sort(b + 1, b + 1 + n);
  for (int t = 0, j = n; t < n; t++) {
    addmod(ans, C((all - ps) / n + n - 1, n - 1));
    ps += n;
    while (j >= 1 && b[j] + t + 1 >= n) {
      ps -= n;
      j--;
    }
  }
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
