#include <bits/stdc++.h>
using namespace std;
int dp[33333][555 * 2], counter[33333];
int siz = 550;
int get(int n, int off, int d) {
  if (d + off <= 0) return 0;
  if (off > siz) return 0;
  if (off < -siz) return 0;
  if (n > 30000) return 0;
  return dp[n][off + siz];
}
int main() {
  int end = 30000;
  int n, d;
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    counter[x]++;
  }
  for (int i = end; i >= d; i--)
    for (int j = -siz; j <= siz; j++) {
      dp[i][j + siz] = counter[i];
      int add = get(i + d + j, j, d);
      add = max(add, get(i + d + j - 1, j - 1, d));
      add = max(add, get(i + d + j + 1, j + 1, d));
      dp[i][j + siz] += add;
    }
  printf("%d\n", dp[d][0 + siz]);
}
