#include <bits/stdc++.h>
using namespace std;
int n, m, ans, fac[2005], inv[2005], a[2005], l[2005], r[2005],
    f[2][2005][2005];
int C(int n, int m) {
  if (n < m) return 0;
  return (long long)fac[n] * inv[m] % 998244353 * inv[n - m] % 998244353;
}
int main() {
  fac[0] = inv[0] = inv[1] = 1;
  for (int i = 1; i < 2005; i++) fac[i] = (long long)fac[i - 1] * i % 998244353;
  for (int i = 2; i < 2005; i++)
    inv[i] =
        (long long)(998244353 - 998244353 / i) * inv[998244353 % i] % 998244353;
  for (int i = 1; i < 2005; i++)
    inv[i] = (long long)inv[i - 1] * inv[i] % 998244353;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    l[i] = max(a[i] - m, 0), r[i] = min(a[i] + m, i);
  }
  f[0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    int p = (i & 1);
    for (int k = 0; k <= i - l[i]; k++)
      for (int j = max(l[i] - r[i - 1] - 1, 0); j < l[i] - l[i - 1]; j++)
        f[p][l[i]][k] =
            (f[p][l[i]][k] + f[p ^ 1][l[i] - j - 1][k + j]) % 998244353;
    for (int j = l[i] + 1; j <= r[i]; j++)
      for (int k = 0; k <= i - j; k++)
        f[p][j][k] = (f[p][j - 1][k + 1] + f[p ^ 1][j - 1][k]) % 998244353;
    for (int j = l[i - 1]; j <= r[i - 1]; j++)
      for (int k = 0; k < i - j; k++)
        if ((l[i] <= j) && (j <= r[i])) {
          f[p][j][k] =
              (f[p][j][k] + (long long)(j + k) * f[p ^ 1][j][k]) % 998244353;
          f[p][j][k + 1] =
              (f[p][j][k + 1] + (long long)(k + 1) * f[p ^ 1][j][k]) %
              998244353;
        }
    for (int j = l[i - 1]; j <= r[i - 1]; j++)
      for (int k = 0; k < i - j; k++) f[p ^ 1][j][k] = 0;
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n - i; j++)
      ans = (ans + (long long)C(n - i, j) * f[n & 1][i][j]) % 998244353;
  printf("%d\n", ans);
  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;
int n, m, ans, fac[2005], inv[2005], a[2005], l[2005], r[2005],
    f[2][2005][2005];
int C(int n, int m) {
  if (n < m) return 0;
  return (long long)fac[n] * inv[m] % 998244353 * inv[n - m] % 998244353;
}
int main() {
  fac[0] = inv[0] = inv[1] = 1;
  for (int i = 1; i < 2005; i++) fac[i] = (long long)fac[i - 1] * i % 998244353;
  for (int i = 2; i < 2005; i++)
    inv[i] =
        (long long)(998244353 - 998244353 / i) * inv[998244353 % i] % 998244353;
  for (int i = 1; i < 2005; i++)
    inv[i] = (long long)inv[i - 1] * inv[i] % 998244353;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    l[i] = max(a[i] - m, 0), r[i] = min(a[i] + m, i);
  }
  f[0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    int p = (i & 1);
    for (int k = 0; k <= i - l[i]; k++)
      for (int j = max(l[i] - r[i - 1] - 1, 0); j < l[i] - l[i - 1]; j++)
        f[p][l[i]][k] =
            (f[p][l[i]][k] + f[p ^ 1][l[i] - j - 1][k + j]) % 998244353;
    for (int j = l[i] + 1; j <= r[i]; j++)
      for (int k = 0; k <= i - j; k++)
        f[p][j][k] = (f[p][j - 1][k + 1] + f[p ^ 1][j - 1][k]) % 998244353;
    for (int j = l[i - 1]; j <= r[i - 1]; j++)
      for (int k = 0; k < i - j; k++)
        if ((l[i] <= j) && (j <= r[i])) {
          f[p][j][k] =
              (f[p][j][k] + (long long)(j + k) * f[p ^ 1][j][k]) % 998244353;
          f[p][j][k + 1] =
              (f[p][j][k + 1] + (long long)(k + 1) * f[p ^ 1][j][k]) %
              998244353;
        }
    for (int j = l[i - 1]; j <= r[i - 1]; j++)
      for (int k = 0; k < i - j; k++) f[p ^ 1][j][k] = 0;
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n - i; j++)
      ans = (ans + (long long)C(n - i, j) * f[n & 1][i][j]) % 998244353;
  printf("%d\n", ans);
  return 0;
}

```