#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e4 + 10, MXM = 500;
int dp[MAXN][MXM];
int a[MAXN];
int main() {
  int n, d, a1;
  cin >> n >> d;
  for (int i = 0; i < n; ++i) {
    cin >> a1;
    ++a[a1];
  }
  for (int i = MAXN - 1; i >= 0; --i)
    for (int j = 1; j < MXM; ++j) {
      if (j - MXM / 2 + d <= 0) continue;
      if (i + d + j - MXM / 2 < MAXN)
        dp[i][j] = max(dp[i + d + j - MXM / 2][j], dp[i][j]);
      if (i + d + j + 1 - MXM / 2 < MAXN && j < MXM - 1)
        dp[i][j] = max(dp[i][j], dp[i + d + j + 1 - MXM / 2][j + 1]);
      if (i + d + j - 1 - MXM / 2 < MAXN && j)
        dp[i][j] = max(dp[i][j], dp[i + d + j - 1 - MXM / 2][j - 1]);
      dp[i][j] += a[i];
    }
  cout << dp[d][MXM / 2];
  return 0;
}
