#include <bits/stdc++.h>
using namespace std;
const long long N = 1e+6 + 5;
long long big = 1e+18 + 3;
long long mod = 1e+9 + 7;
long long ar[N];
long long z, n;
bool check(long long nop) {
  long long ptr = nop + 1;
  for (long long i = 1; i <= nop; i++) {
    if (ptr == n + 1) return false;
    while (ar[ptr] < ar[i] + z) {
      if (ptr == n) break;
      ptr++;
    }
    if (ar[ptr] < ar[i] + z)
      return false;
    else
      ptr++;
  }
  return true;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> z;
  for (long long i = 1; i <= n; i++) cin >> ar[i];
  sort(ar + 1, ar + 1 + n);
  long long low = 1;
  long long high = n / 2;
  long long ans = 0;
  while (low <= high) {
    long long mid = (low + high) / 2;
    if (check(mid))
      ans = mid, low = mid + 1;
    else
      high = mid - 1;
  }
  cout << ans << "\n";
}
