#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int arr[N];
int n, z;
void input() {
  cin >> n >> z;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
}
int bin_search(int l, int r) {
  if (l == r) {
    return l;
  }
  int q = l + r + 1 >> 1;
  for (int i = 0, j = n - q; i < q; ++i, ++j) {
    if (arr[j] - arr[i] < z) {
      return bin_search(l, q - 1);
    }
  }
  return bin_search(q, r);
}
void solve() { cout << bin_search(0, n / 2) << "\n"; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  input();
  solve();
}
