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;
void exgcd(int a, int b, int& x, int& y) {
  if (!b) {
    x = 1, y = 0;
  } else {
    exgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
}
int inv(int a, int n) {
  int x, y;
  exgcd(a, n, x, y);
  return (x < 0) ? (x + n) : (x);
}
const int Mod = 998244353;
template <const int Mod = ::Mod>
class Z {
 public:
  int v;
  Z() : v(0) {}
  Z(int x) : v(x) {}
  Z(long long x) : v(x % Mod) {}
  friend Z operator+(const Z& a, const Z& b) {
    int x;
    return Z(((x = a.v + b.v) >= Mod) ? (x - Mod) : (x));
  }
  friend Z operator-(const Z& a, const Z& b) {
    int x;
    return Z(((x = a.v - b.v) < 0) ? (x + Mod) : (x));
  }
  friend Z operator*(const Z& a, const Z& b) { return Z(a.v * 1ll * b.v); }
  friend Z operator~(const Z& a) { return inv(a.v, Mod); }
  friend Z operator-(const Z& a) { return Z(0) - a; }
  Z& operator+=(Z b) { return *this = *this + b; }
  Z& operator-=(Z b) { return *this = *this - b; }
  Z& operator*=(Z b) { return *this = *this * b; }
  friend bool operator==(const Z& a, const Z& b) { return a.v == b.v; }
};
Z<> qpow(Z<> a, int p) {
  Z<> rt = Z<>(1), pa = a;
  for (; p; p >>= 1, pa = pa * pa) {
    if (p & 1) {
      rt = rt * pa;
    }
  }
  return rt;
}
const int N = 1e5 + 5, V = 2e6 + 5;
int n, sum;
int a[N], c[N];
Z<> fac[V], _fac[V];
void init_fac(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; i++) {
    fac[i] = fac[i - 1] * i;
  }
  _fac[n] = ~fac[n];
  for (int i = n; i; i--) {
    _fac[i - 1] = _fac[i] * i;
  }
}
Z<> comb(int n, int m) {
  return (n < m) ? (0) : (fac[n] * _fac[m] * _fac[n - m]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    sum += a[i];
  }
  init_fac(sum + n);
  int cri = 0;
  sort(a + 1, a + n + 1);
  for (int i = 1; i < n; i++) {
    if (a[i + 1] < i) {
      cri = i;
      break;
    }
  }
  Z<> ans = 0;
  if (cri) {
    int num = 0;
    for (int i = 0; i < cri; i++) {
      while (num < n && a[num + 1] < i) num++;
      ans += comb(i - num + n - 1, n - 1);
    }
  } else {
    sum = 1;
    for (int i = 1; i <= n; i++) {
      sum += a[i] / n;
      c[a[i] % n]++;
    }
    for (int i = 0; i < n; i++) {
      sum += c[n - i] - 1;
      ans += comb(sum + n - 1, n - 1);
    }
  }
  printf("%d\n", ans.v);
  return 0;
}