#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 30 * 1000 + 20;
const int MAXN = 30 * 1000 + 15;
const int MLOG = 18;
const int NMAX = 251;
short n, d;
struct jojo {
  short A[2][NMAX + 1] = {{}, {}};
  short inf = -INF;
  short& operator[](short a) {
    if (a >= -NMAX && a <= NMAX) return A[a >= 0][abs(a)];
    return inf;
  }
} dp[MAXN];
int32_t main() {
  short ans = 0;
  cin >> n >> d;
  short g[MAXN] = {};
  for (short i = 0; i < n; i++) {
    short a;
    cin >> a;
    g[a]++;
  }
  for (short i = 0; i < MAXN; i++)
    for (short j = -NMAX; j <= NMAX; j++) dp[i][j] = -INF;
  dp[d][0] = g[d] + g[0];
  ans = dp[d][0];
  for (short i = d + 1; i < MAXN; i++)
    for (short j = -NMAX; j <= NMAX; j++)
      if (i - j - d >= 0 && i - j - d < i) {
        dp[i][j] = max({dp[i - j - d][j - 1], dp[i - j - d][j],
                        dp[i - j - d][j + 1]}) +
                   g[i];
        ans = max(ans, dp[i][j]);
      }
  cout << ans;
}
