#include <bits/stdc++.h>
using namespace std;
const int MAXN = 30000, MAXRAD = 280;
long long dp[MAXN + 10][MAXRAD * 2 + 10], mark[MAXN + 10], ans, n, d;
bool isOkayJump(int jump, int start) {
  if (jump > start || jump <= 0 || jump >= 30000) return false;
  if (start - jump < d && start + jump >= 30000) return false;
  return true;
}
int main() {
  cin >> n >> d;
  for (int i = 0; i <= 30000; i++)
    for (int j = 0; j <= 2 * MAXRAD; j++) dp[i][j] = -1e9;
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    mark[c]++;
  }
  dp[d][MAXRAD] = mark[d];
  for (int i = d + 1; i <= 30000; i++) {
    for (int j = 0; j <= 2 * MAXRAD; j++) {
      int currentjump = d + (j - MAXRAD);
      if (!isOkayJump(currentjump, i)) continue;
      if (i - currentjump < d) continue;
      int lastjump1 = currentjump - 1, lastjump2 = currentjump,
          lastjump3 = currentjump + 1, ind1 = j - 1, ind2 = j, ind3 = j + 1,
          lastp = i - currentjump;
      if (isOkayJump(lastjump1, lastp) && dp[lastp][ind1] >= 0 && ind1 >= 0 &&
          ind1 <= 2 * MAXRAD)
        dp[i][j] = max(dp[lastp][ind1] + mark[i], dp[i][j]);
      if (isOkayJump(lastjump2, lastp) && dp[lastp][ind2] >= 0 && ind2 >= 0 &&
          ind2 <= 2 * MAXRAD)
        dp[i][j] = max(dp[lastp][ind2] + mark[i], dp[i][j]);
      if (isOkayJump(lastjump3, lastp) && dp[lastp][ind3] >= 0 && ind3 >= 0 &&
          ind3 <= 2 * MAXRAD)
        dp[i][j] = max(dp[lastp][ind3] + mark[i], dp[i][j]);
    }
  }
  int ansind, ansjum;
  for (int i = 0; i <= 30000; i++)
    for (int j = 0; j <= MAXRAD * 2; j++) ans = max(ans, dp[i][j]);
  cout << ans;
  return 0;
}
