#include <bits/stdc++.h>
using namespace std;
int n, d, a[100010];
long long ans;
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    int j1 = lower_bound(a, a + n, a[i] - d) - a;
    int j2 = upper_bound(a, a + n, a[i] + d) - a;
    int tmp = j2 - j1;
    if (j1 <= i && i < j2) tmp--;
    ans += tmp;
  }
  cout << ans << endl;
  return 0;
}
