#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, k, i, j, d;
  cin >> n >> d;
  long int ar[n], c;
  for (i = 0; i < n; i++) cin >> ar[i];
  sort(ar, ar + n);
  i = 0;
  j = n - 1;
  c = 0;
  while (j > i) {
    if (ar[j] - ar[i] <= d) {
      break;
    } else if (ar[j - 1] - ar[i] <= d) {
      c++;
      break;
    } else if (ar[j] - ar[i + 1] <= d) {
      c++;
      break;
    } else if (ar[j - 1] - ar[i + 1] <= d) {
      c = c + 2;
      break;
    } else {
      i++;
      j--;
      c = c + 2;
    }
  }
  cout << c;
  return 0;
}
