#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, z;
  cin >> n >> z;
  map<int, int64_t> lo, hi;
  vector<int> v;
  for (int i = 0, x; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  for (int i = n / 2; i < n; i++) {
    lo[v[i]]++;
  }
  int64_t ans = 0;
  for (int i = 0; i < n / 2; i++) {
    auto w = lo.lower_bound(v[i] + z);
    if (w != lo.end()) {
      lo[w->first]--;
      ans++;
      if (lo[w->first] == 0) lo.erase(w->first);
    }
  }
  cout << ans << '\n';
  return 0;
}
