#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e4 + 9, N = 500;
int m[MAX][N], n, d, c[MAX], ans, res;
bool b[MAX][N];
template <class P, class Q>
inline void smax(P &a, Q b) {
  if (a < b) a = b;
}
int main() {
  cin >> n >> d;
  for (int i = 0, x; i < n; i++) cin >> x, c[x]++;
  b[d][N / 2] = true;
  for (int i = 0; i < MAX; i++)
    for (int j = 0; j < N; j++)
      if (b[i][j]) {
        m[i][j] += c[i];
        if (j + i + d - N / 2 < MAX)
          smax(m[j + i + d - N / 2][j], m[i][j]),
              b[j + i + d - N / 2][j] = true;
        if (j + i + 1 + d - N / 2 < MAX)
          smax(m[j + i + 1 + d - N / 2][j + 1], m[i][j]),
              b[i + j + 1 + d - N / 2][j + 1] = true;
        if (j + i - 1 + d - N / 2 < MAX && j + i - 1 + d - N / 2 > i)
          smax(m[j + i - 1 + d - N / 2][j - 1], m[i][j]),
              b[i + j - 1 + d - N / 2][j - 1] = true;
        ans = max(ans, m[i][j]);
      }
  cout << ans;
}
