#include <bits/stdc++.h>
using namespace std;
const int P = 998244353;
int norm(int x) { return x >= P ? x - P : x; }
int reduce(int x) { return x < 0 ? x + P : x; }
int neg(int x) { return x ? P - x : 0; }
void add(int& x, int y) {
  if ((x += y - P) < 0) x += P;
}
void sub(int& x, int y) {
  if ((x -= y) < 0) x += P;
}
void fam(int& x, int y, int z) { x = (x + y * (unsigned long long)z) % P; }
int mpow(int x, unsigned k) {
  if (k == 0) return 1;
  int ret = mpow(x * (unsigned long long)x % P, k >> 1);
  if (k & 1) ret = ret * (unsigned long long)x % P;
  return ret;
}
int quo2(int x) { return ((x & 1) ? x + P : x) >> 1; }
int dp[2010][105], tmp[2010][105], pmt[2010][105];
int b[2010];
int C[2010][2010], fac[2010], ifac[2010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= N; ++i) cin >> b[i];
  fac[0] = 1;
  for (int i = 1; i <= N; ++i) fac[i] = fac[i - 1] * (unsigned long long)i % P;
  ifac[N] = mpow(fac[N], P - 2);
  for (int i = N; i; --i) ifac[i - 1] = ifac[i] * (unsigned long long)i % P;
  dp[0][K] = 1;
  for (int i = 1; i <= N; ++i) {
    int L = b[i - 1] - K, R = b[i - 1] + K;
    int L1 = b[i] - K, R1 = b[i] + K;
    memset(tmp, 0, sizeof(tmp));
    memset(pmt, 0, sizeof(pmt));
    for (int j = 0; j != i; ++j) {
      for (int l = L; l <= R; ++l) {
        add(tmp[j][l - L], dp[j][l - L] * (unsigned long long)(l + j) % P);
        add(tmp[j + 1][l - L], dp[j][l - L]);
        if (l <= R1) {
          if (l >= L1) {
            add(pmt[j][l - L1 + 1], dp[j][l - L]);
          } else if (j >= L1 - l - 1) {
            add(pmt[j - (L1 - l - 1)][0], dp[j][l - L] *
                                              (unsigned long long)fac[j] % P *
                                              ifac[j - (L1 - l - 1)] % P);
          }
        }
      }
    }
    for (int j = i; j >= 0; --j)
      for (int k = 1; k <= K * 2; ++k)
        add(pmt[j][k], pmt[j + 1][k - 1] * (unsigned long long)(j + 1) % P);
    for (int j = 0; j <= i; ++j)
      for (int k = L; k <= R; ++k)
        if (k >= L1 && k <= R1) add(pmt[j][k - L1], tmp[j][k - L]);
    memcpy(dp, pmt, sizeof(pmt));
  }
  for (int i = 0; i <= N; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j) C[i][j] = norm(C[i - 1][j - 1] + C[i - 1][j]);
  }
  int t = b[N] - K, L = max(0, b[N] - K), R = min(N, b[N] + K);
  int ans = 0;
  for (int i = 0; i <= N; ++i)
    for (int j = L; j <= R; ++j)
      ans =
          (ans + dp[i][j - t] * (unsigned long long)C[N - j][i] % P * fac[i]) %
          P;
  cout << ans << '\n';
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

For an array c of nonnegative integers, MEX(c) denotes the smallest nonnegative integer that doesn't appear in it. For example, MEX([0, 1, 3]) = 2, MEX([42]) = 0.

You are given integers n, k, and an array [b_1, b_2, …, b_n].

Find the number of arrays [a_1, a_2, …, a_n], for which the following conditions hold:

  * 0 ≤ a_i ≤ n for each i for each i from 1 to n.

  * |MEX([a_1, a_2, …, a_i]) - b_i| ≤ k for each i from 1 to n.




As this number can be very big, output it modulo 998 244 353.

Input

The first line of the input contains two integers n, k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 50).

The second line of the input contains n integers b_1, b_2, …, b_n (-k ≤ b_i ≤ n+k) — elements of the array b.

Output

Output a single integer — the number of arrays which satisfy the conditions from the statement, modulo 998 244 353.

Examples

Input


4 0
0 0 0 0


Output


256


Input


4 1
0 0 0 0


Output


431


Input


4 1
0 0 1 1


Output


509


Input


5 2
0 0 2 2 0


Output


6546


Input


3 2
-2 0 4


Output


11

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int P = 998244353;
int norm(int x) { return x >= P ? x - P : x; }
int reduce(int x) { return x < 0 ? x + P : x; }
int neg(int x) { return x ? P - x : 0; }
void add(int& x, int y) {
  if ((x += y - P) < 0) x += P;
}
void sub(int& x, int y) {
  if ((x -= y) < 0) x += P;
}
void fam(int& x, int y, int z) { x = (x + y * (unsigned long long)z) % P; }
int mpow(int x, unsigned k) {
  if (k == 0) return 1;
  int ret = mpow(x * (unsigned long long)x % P, k >> 1);
  if (k & 1) ret = ret * (unsigned long long)x % P;
  return ret;
}
int quo2(int x) { return ((x & 1) ? x + P : x) >> 1; }
int dp[2010][105], tmp[2010][105], pmt[2010][105];
int b[2010];
int C[2010][2010], fac[2010], ifac[2010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= N; ++i) cin >> b[i];
  fac[0] = 1;
  for (int i = 1; i <= N; ++i) fac[i] = fac[i - 1] * (unsigned long long)i % P;
  ifac[N] = mpow(fac[N], P - 2);
  for (int i = N; i; --i) ifac[i - 1] = ifac[i] * (unsigned long long)i % P;
  dp[0][K] = 1;
  for (int i = 1; i <= N; ++i) {
    int L = b[i - 1] - K, R = b[i - 1] + K;
    int L1 = b[i] - K, R1 = b[i] + K;
    memset(tmp, 0, sizeof(tmp));
    memset(pmt, 0, sizeof(pmt));
    for (int j = 0; j != i; ++j) {
      for (int l = L; l <= R; ++l) {
        add(tmp[j][l - L], dp[j][l - L] * (unsigned long long)(l + j) % P);
        add(tmp[j + 1][l - L], dp[j][l - L]);
        if (l <= R1) {
          if (l >= L1) {
            add(pmt[j][l - L1 + 1], dp[j][l - L]);
          } else if (j >= L1 - l - 1) {
            add(pmt[j - (L1 - l - 1)][0], dp[j][l - L] *
                                              (unsigned long long)fac[j] % P *
                                              ifac[j - (L1 - l - 1)] % P);
          }
        }
      }
    }
    for (int j = i; j >= 0; --j)
      for (int k = 1; k <= K * 2; ++k)
        add(pmt[j][k], pmt[j + 1][k - 1] * (unsigned long long)(j + 1) % P);
    for (int j = 0; j <= i; ++j)
      for (int k = L; k <= R; ++k)
        if (k >= L1 && k <= R1) add(pmt[j][k - L1], tmp[j][k - L]);
    memcpy(dp, pmt, sizeof(pmt));
  }
  for (int i = 0; i <= N; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j) C[i][j] = norm(C[i - 1][j - 1] + C[i - 1][j]);
  }
  int t = b[N] - K, L = max(0, b[N] - K), R = min(N, b[N] + K);
  int ans = 0;
  for (int i = 0; i <= N; ++i)
    for (int j = L; j <= R; ++j)
      ans =
          (ans + dp[i][j - t] * (unsigned long long)C[N - j][i] % P * fac[i]) %
          P;
  cout << ans << '\n';
  return 0;
}

```