#include <bits/stdc++.h>
using namespace std;
const int INF = 100000001;
const double EPS = 10e-9;
int main() {
  ios_base::sync_with_stdio(false);
  int n, d;
  cin >> n >> d;
  vector<int> p(30001, 0);
  int x;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    p[x]++;
  }
  vector<vector<long long>> v(60001, vector<long long>(501, 0));
  for (int i = 30000; i >= (0); --i) {
    for (int j = 0; j < 500; ++j) {
      int k = d + (j - 250);
      if (k <= 0 || k > i) {
        continue;
      }
      int a = i + k - 1;
      int b = i + k;
      int c = i + k + 1;
      if (j >= 1 && a > i && a <= 60000) {
        v[i][j] = max(v[i][j], v[a][j - 1] + p[i]);
      }
      if (b > i && b <= 60000) {
        v[i][j] = max(v[i][j], v[b][j] + p[i]);
      }
      if (j <= 500 && c > i && c <= 60000) {
        v[i][j] = max(v[i][j], v[c][j + 1] + p[i]);
      }
    }
  }
  cout << v[d][250] << endl;
}
