#include <bits/stdc++.h>
using namespace std;
int dp[3 * 10007][507];
int cnt[3 * 10007], ans;
int main() {
  int i, j, n, d;
  while (scanf("%d%d", &n, &d) != EOF) {
    memset(cnt, 0, sizeof(cnt));
    for (i = 1; i <= n; i++) {
      scanf("%d", &j);
      cnt[j]++;
    }
    memset(dp, -1, sizeof(dp));
    dp[d][250] = cnt[d];
    ans = dp[d][250];
    for (i = d; i <= 30000; i++) {
      for (j = 1; j <= 500; j++) {
        if (dp[i][j] == -1) continue;
        int to = i + d + j - 250;
        if (to <= 30000) {
          dp[to][j] = max(dp[to][j], dp[i][j] + cnt[to]);
          ans = max(ans, dp[to][j]);
        }
        if (to + 1 <= 30000) {
          dp[to + 1][j + 1] = max(dp[to + 1][j + 1], dp[i][j] + cnt[to + 1]);
          ans = max(ans, dp[to + 1][j + 1]);
        }
        if (to <= 30000 && to - i > 1) {
          dp[to - 1][j - 1] = max(dp[to - 1][j - 1], dp[i][j] + cnt[to - 1]);
          ans = max(ans, dp[to - 1][j - 1]);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
