#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, d, i;
  cin >> n >> d;
  int arr[n];
  for (i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  int p1, p2 = 0, ans = 0, temp;
  for (p1 = 0; p1 < n; p1++) {
    while (p2 < n and arr[p2] - arr[p1] <= d) p2++;
    temp = p2 - p1 - 1;
    if (temp > 0) ans += 2 * temp;
  }
  cout << ans << endl;
  return 0;
}
