#include <bits/stdc++.h>
using namespace std;
long long all[200005];
bool have[200005] = {0};
int main() {
  long long N, M, ans = 0, i, t, l, r = 1, now = 0, ok;
  scanf("%lld %lld", &N, &M);
  for (i = 0; i < N; i++) scanf("%lld", &all[i]);
  sort(all, all + N);
  l = 0;
  r = (N / 2 + 1);
  while ((r - l) / 2) {
    ok = 1;
    for (i = 0; i < (l + r) / 2; i++) {
      if (all[N - (l + r) / 2 + i] - all[i] < M) ok = 0;
    }
    if (ok)
      l = (l + r) / 2;
    else
      r = (l + r) / 2;
  }
  printf("%lld\n", l);
  return 0;
}
