#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int maxn = 1e5 + 7;
int a[maxn];
int main() {
  int n, d;
  scanf("%d%d", &n, &d);
  map<int, int> m;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int tmp;
    scanf("%d", &tmp);
    v.emplace_back(tmp);
    m[tmp]++;
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  int ln = (int)v.size(), ans = 0;
  for (int i = 0; i <= ln - 1; i++) {
    ans += (m[v[i]] - 1) * m[v[i]];
    for (int j = i + 1; j < ln; j++) {
      if (v[j] - v[i] <= d) ans += 2 * m[v[j]] * m[v[i]];
    }
  }
  printf("%d\n", ans);
  return 0;
}
