#include <bits/stdc++.h>
using namespace std;
int a[30009], n, d;
int dp[30009][700];
int main() {
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a[x]++;
  }
  int mid = 350;
  for (int i = 0; i <= 30000; i++)
    for (int j = 0; j < 700; j++) dp[i][j] = -1e9;
  dp[d][mid] = a[d] + a[0];
  int step = 0;
  int ans = 0;
  for (int i = 0; i <= 30000; i++) {
    for (int j = 0; j < 700; j++) {
      if (dp[i][j] < 0) continue;
      ans = max(ans, dp[i][j]);
      step = j - mid + d;
      if (step > 0 && i + step <= 30000) {
        dp[i + step][step - d + mid] =
            max(dp[i + step][step - d + mid], dp[i][j] + a[i + step]);
      }
      step++;
      if (step > 0 && i + step <= 30000) {
        dp[i + step][step - d + mid] =
            max(dp[i + step][step - d + mid], dp[i][j] + a[i + step]);
      }
      step -= 2;
      if (step > 0 && i + step <= 30000) {
        dp[i + step][step - d + mid] =
            max(dp[i + step][step - d + mid], dp[i][j] + a[i + step]);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
