#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
struct BIT_RAQ {
 public:
  BIT_RAQ(int n) : _n(n) {
    for (int i = 0; i < 2; ++i) data[i].assign(_n, 0);
  }
  BIT_RAQ(std::vector<T> v) : _n(v.size()) {
    for (int i = 0; i < 2; ++i) data[i].assign(_n, 0);
    for (int i = 0; i < _n; ++i) {
      add(i, i + 1, v[i]);
    }
  }
  void add(int l, int r, T x) {
    ++l, ++r;
    add_sub(0, l, -x * (l - 1));
    add_sub(0, r, x * (r - 1));
    add_sub(1, l, x);
    add_sub(1, r, -x);
  }
  T sum(int l, int r) {
    T sum1 = sum_sub(0, r) + sum_sub(1, r) * r;
    T sum2 = sum_sub(0, l) + sum_sub(1, l) * l;
    return sum1 - sum2;
  }

 private:
  int _n;
  std::vector<T> data[2];
  void add_sub(int p, int i, T x) {
    while (i <= _n) {
      data[p][i - 1] += x;
      i += i & -i;
    }
  }
  T sum_sub(int p, int i) {
    T s = 0;
    while (i > 0) {
      s += data[p][i - 1];
      i -= i & -i;
    }
    return s;
  }
};
int main() {
  ll i, j;
  ll n, k;
  cin >> n >> k;
  ll INF = 300000 + 1;
  BIT_RAQ<ll> bit(INF);
  for (i = 0; i < n; ++i) {
    ll a;
    cin >> a;
    ll left = max(a - k, 0ll);
    ll right = min(a + k + 1, INF);
    bit.add(left, right, 1);
  }
  ll ans = -1;
  for (i = 0; i < INF; ++i) {
    ans = max(ans, bit.sum(i, i + 1));
    cout << bit.sum(i, i + 1) << endl;
  }
  cout << ans - 1 << endl;
  return 0;
}
