#include <bits/stdc++.h>
using namespace std;
const int MAX = 30001;
int n, d;
vector<int> p;
int main() {
  cin >> n >> d;
  p = vector<int>(MAX, 0);
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    ++p[k];
  }
  int k1 = 1, k2 = 1, bot, top;
  while (k1 * d + (long long)k1 * (k1 - 1) / 2 <= MAX) ++k1;
  while (k2 * d - (long long)k2 * (k2 - 1) / 2 <= MAX and k2 < d) ++k2;
  bot = max(0, d - k2), top = d + k1;
  int m = top - bot + 10;
  vector<vector<long long>> dp(MAX, vector<long long>(m, -1));
  dp[d][d - bot] = 0;
  long long res = 0;
  for (int i = d; i < MAX; ++i) {
    for (int j = 1; j < m; ++j) {
      long long &ad = dp[i][j];
      if (ad != -1) {
        ad += p[i];
        for (int k = -1; k <= 1; ++k) {
          if (j + bot + k < 1 or j + k < 0) continue;
          if (i + j + bot + k >= MAX)
            res = max(res, ad);
          else
            dp[i + j + bot + k][j + k] = max(dp[i + j + bot + k][j + k], ad);
        }
      }
    }
  }
  cout << res << '\n';
}
