#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
  return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
  return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t = buf;
inline int fetch() {
  if (s == t) {
    t = (s = buf) + fread(buf, 1, bufl, stdin);
    if (s == t) return EOF;
  }
  return *s++;
}
inline int ty() {
  int a = 0;
  int b = 1, c = fetch();
  while (!isdigit(c)) b ^= c == '-', c = fetch();
  while (isdigit(c)) a = a * 10 + c - 48, c = fetch();
  return b ? a : -a;
}
}  // namespace ae86
using ae86::ty;
const int _ = 100007, __ = 2000007, mo = 998244353;
template <typename T1, typename T2>
inline T1 ad(T1 &a, T2 b) {
  return a = a + b >= mo ? a + b - mo : a + b;
}
template <typename T1, typename T2>
inline T1 dl(T1 &a, T2 b) {
  return a = a >= b ? a - b : a - b + mo;
}
template <typename T1, typename T2>
inline T1 add(T1 a, T2 b) {
  return a + b >= mo ? a + b - mo : a + b;
}
template <typename T1, typename T2>
inline T1 del(T1 a, T2 b) {
  return a >= b ? a - b : a - b + mo;
}
long long powa(long long a, long long t) {
  long long b = 1;
  a = (a + mo) % mo;
  while (t) {
    if (t & 1) b = b * a % mo;
    a = a * a % mo, t >>= 1;
  }
  return b;
}
inline long long inva(long long a) { return powa(a, mo - 2); }
long long jc[__], rjc[__];
void fuck(int n = __ - 1) {
  jc[0] = jc[1] = rjc[0] = 1;
  for (int i = 2; i <= n; i++) jc[i] = jc[i - 1] * i % mo;
  rjc[n] = inva(jc[n]);
  for (int i = n - 1; i >= 1; i--) rjc[i] = rjc[i + 1] * (1ll + i) % mo;
}
long long C(int n, int m) {
  if (n < m || n < 0 || m < 0) return 0;
  return jc[n] * rjc[m] % mo * rjc[n - m] % mo;
}
int n, val[_] = {0}, mxval = 0, cnt[__] = {0};
long long ned[__] = {0};
int main() {
  ios::sync_with_stdio(0), cout.tie(nullptr);
  fuck();
  n = ty();
  for (int i = 1; i <= n; i++)
    val[i] = ty(), mxval = max(mxval, val[i]), cnt[val[i] + 1]++;
  for (int i = 1; i <= n; i++)
    for (int j = val[i] + 1; j <= mxval; j += n) ned[j]++;
  long long ans = 1, los = 0, res = n;
  for (int i = 1; i <= mxval; i++) {
    los++, res -= cnt[i];
    if (los < ned[i]) break;
    los -= ned[i], ad(ans, C(los + n - 1, n - 1));
    if (los >= res) dl(ans, C(los + n - 1 - res, n - 1));
  }
  cout << ans << lf;
  return 0;
}
