#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  ;
  deque<int> d1;
  deque<int>::iterator itr1, itr2;
  int n, dif, cntr = 0;
  cin >> n >> dif;
  for (int j = 0; j < n; ++j) {
    int a;
    cin >> a;
    d1.push_back(a);
  }
  sort(d1.begin(), d1.end());
  for (int j = 0; j < n; ++j) {
    itr1 = d1.begin() + j - 1;
    itr2 = d1.begin() + j + 1;
    while (itr1 != d1.begin() - 1 && (d1[j] - *itr1) <= dif) {
      ++cntr;
      --itr1;
    }
    while (itr2 != d1.end() && (*itr2 - d1[j]) <= dif) {
      ++cntr;
      ++itr2;
    }
  }
  cout << cntr << endl;
}
