#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  vector<int> a(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
  }
  int cnt = 0;
  int r;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      r = abs(a[i] - a[j]);
      if (r == K) ++cnt;
    }
  }
  printf("%d\n", cnt - 1);
}
