Problem: At Moscow Workshops ICPC team gets a balloon for each problem they solved first. Team MSU Red Panda got so many balloons that they didn't know how to spend them. So they came up with a problem with them.

There are several balloons, not more than 10^6 in total, each one is colored in one of k colors. We can perform the following operation: choose k-1 balloons such that they are of k-1 different colors, and recolor them all into remaining color. We can perform this operation any finite number of times (for example, we can only perform the operation if there are at least k-1 different colors among current balls).

How many different balloon configurations can we get? Only number of balloons of each color matters, configurations differing only by the order of balloons are counted as equal. As this number can be very large, output it modulo 998244353.

Input

The first line contains a single integer k (2 ≤ k ≤ 10^5) —the number of colors.

The second line contains k integers a_1, a_2, …, a_k (0 ≤ a_i) —initial configuration of balloons. a_i is number of balloons of color i. The total number of balloons doesn't exceed 10^6. In other words,

a_1 + a_2 + a_3 + … + a_k ≤ 10^6.

Output

Output number of possible configurations modulo 998244353.

Examples

Input


3
0 1 2


Output


3


Input


4
1 1 1 1


Output


5

Input


5
0 0 1 2 3


Output


1

Input


3
2 2 8


Output


31

Note

In the first example, there are 3 configurations we can get: [0, 1, 2], [2, 0, 1], [1, 2, 0].

In the second example, we can apply the operation not more than once, and possible configurations are: [1, 1, 1, 1], [0, 0, 0, 4], [0, 0, 4, 0], [0, 4, 0, 0], [4, 0, 0, 0]. 

In the third example, we can't apply any operations, so the only achievable configuration is the starting one.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
template <class T>
inline void ckmin(T& a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void ckmax(T& a, T b) {
  if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
using VI = vector<int>;
template <typename base_type, base_type _MOD>
class IntMod {
 public:
  static const int INVERSE_CACHE_SIZE = (1 << 20);
  static base_type MOD;
  static void set_mod(base_type new_mod) { MOD = new_mod; }
  base_type n;
  IntMod(long long d = 0) { n = (d >= 0 ? d % MOD : (d % MOD + MOD) % MOD); }
  virtual ~IntMod() = default;
  IntMod operator-() const { return build(n == 0 ? 0 : MOD - n); }
  IntMod& operator+=(IntMod a) {
    n = (n >= MOD - a.n ? n - MOD + a.n : n + a.n);
    return *this;
  }
  IntMod& operator-=(IntMod a) {
    n = (n >= a.n) ? n - a.n : n - a.n + MOD;
    return *this;
  }
  IntMod& operator*=(IntMod a) {
    *this = *this * a;
    return *this;
  }
  IntMod& operator/=(IntMod a) {
    *this = *this / a;
    return *this;
  }
  static IntMod build(base_type n) {
    IntMod r;
    r.n = n;
    return r;
  }
  static base_type inverse_cache[INVERSE_CACHE_SIZE];
  static bool inverse_cache_ready;
  friend IntMod inverse(IntMod n) { return build(inverse_internal(n.n)); }
  static base_type inverse_internal(base_type n) {
    if (!inverse_cache_ready) {
      inverse_cache_ready = true;
      inverse_cache[0] = 0;
      inverse_cache[1] = 1;
      for (int n = 2; n < INVERSE_CACHE_SIZE; ++n)
        inverse_cache[n] =
            (MOD -
             (base_type)((long long)inverse_cache[MOD % n] * (MOD / n) % MOD));
    }
    return n < INVERSE_CACHE_SIZE
               ? inverse_cache[n]
               : MOD - (base_type)((long long)inverse_internal(MOD % n) *
                                   (MOD / n) % MOD);
  }
  friend bool operator==(IntMod a, IntMod b) { return a.n == b.n; }
  friend bool operator!=(IntMod a, IntMod b) { return a.n != b.n; }
  friend IntMod operator+(IntMod a, IntMod b) {
    return build(a.n >= MOD - b.n ? a.n - MOD + b.n : a.n + b.n);
  }
  friend IntMod operator-(IntMod a, IntMod b) {
    return build(a.n >= b.n ? a.n - b.n : a.n - b.n + MOD);
  }
  friend IntMod operator*(IntMod a, IntMod b) {
    return build(
        static_cast<base_type>(static_cast<long long>(a.n) * b.n % MOD));
  }
  friend IntMod operator/(IntMod a, IntMod b) { return a * inverse(b); }
  friend IntMod pow(IntMod p, long long e) {
    if (e <= 0) return IntMod(1);
    IntMod r = IntMod(1);
    while (1) {
      if (e & 1) r *= p;
      e /= 2;
      if (e)
        p = p * p;
      else
        break;
    }
    return r;
  }
  friend istream& operator>>(istream& stream, IntMod& a) {
    stream >> a.n;
    return stream;
  }
  friend ostream& operator<<(ostream& stream, const IntMod& a) {
    stream << a.n;
    return stream;
  }
};
template <typename base_type, base_type _MOD>
base_type IntMod<base_type, _MOD>::inverse_cache[INVERSE_CACHE_SIZE];
template <typename base_type, base_type _MOD>
bool IntMod<base_type, _MOD>::inverse_cache_ready;
template <typename base_type, base_type _MOD>
base_type IntMod<base_type, _MOD>::MOD = _MOD;
using Int = IntMod<int, (998244353)>;
const int maxsize = (2 << 20);
Int permutation[maxsize];
Int permutation_inv[maxsize];
Int choose(int n, int m) {
  return (m < 0 || m > n
              ? 0
              : permutation[n] * permutation_inv[m] * permutation_inv[n - m]);
}
void prepare() {
  permutation[0] = permutation_inv[0] = 1;
  for (int i = (1); i < (maxsize); ++i) {
    permutation[i] = permutation[i - 1] * i;
    permutation_inv[i] = permutation_inv[i - 1] / i;
  }
}
Int solve(VI a) {
  int n = ((int)a.size());
  sort(a.begin(), a.end());
  vector<long long> c(n);
  for (int p : a) ++c[min(n - 1, p)];
  vector<long long> sc(n + 1);
  for (int i = 0; i < (n); ++i) sc[i + 1] = sc[i] + c[i];
  for (int i = 0; i < (n); ++i)
    if (a[i] < i) {
      Int ret = 0;
      for (int c = 0; c < (i); ++c) ret += choose(c - sc[c] + n - 1, n - 1);
      return ret;
    }
  Int ret = 0;
  long long sa = 0, sb = 0;
  for (int p : a) sa += p, sb += p % n;
  c = vector<long long>(n);
  for (int p : a) ++c[p % n];
  sc = vector<long long>(n + 1);
  for (int i = 0; i < (n); ++i) sc[i + 1] = sc[i] + c[i];
  for (long long m = 0; m < n; m++) {
    long long d = sb + m * n - n * (n - sc[n - m]);
    if (d <= sa) ret += choose((sa - d) / n + n - 1, n - 1);
  }
  return ret;
}
int main() {
  std::ios::sync_with_stdio(false);
  prepare();
  int n;
  while (cin >> n) {
    VI a(n);
    for (int i = 0; i < (n); ++i) cin >> a[i];
    Int ret = solve(a);
    printf("%d\n", ret.n);
    break;
  }
  return 0;
}