Problem: In the last mission, MDCS has successfully shipped N AI robots to Mars. Before they start exploring, system initialization is required so they are arranged in a line. Every robot can be described with three numbers: position (x_i), radius of sight (r_i) and IQ (q_i).

Since they are intelligent robots, some of them will talk if they see each other. Radius of sight is inclusive, so robot can see other all robots in range [x_i - r_i, x_i + r_i]. But they don't walk to talk with anybody, but only with robots who have similar IQ. By similar IQ we mean that their absolute difference isn't more than K. 

Help us and calculate how many pairs of robots are going to talk with each other, so we can timely update their software and avoid any potential quarrel.

Input

The first line contains two integers, numbers N (1 ≤ N ≤ 10^5)  and K (0 ≤ K ≤ 20).

Next N lines contain three numbers each x_i, r_i, q_i (0 ≤ x_i,r_i,q_i ≤ 10^9) — position, radius of sight and IQ of every robot respectively.

Output

Output contains only one number — solution to the problem.

Example

Input

3 2
3 6 1
7 3 10
10 5 8


Output

1

Note

The first robot can see the second, but not vice versa. The first robot can't even see the third. The second and the third robot can see each other and their IQs don't differ more than 2 so only one conversation will happen.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 102000;
int n, k;
struct node {
  int x, r, q, nb;
} A[maxn];
struct edge {
  int x, r, dr;
};
vector<node> vec[maxn];
vector<edge> ff[maxn];
int cmp(node a, node b) { return a.x < b.x; }
int cmpp(edge a, edge b) { return a.x < b.x; }
int IQ[maxn], iqsz;
int lisan[maxn], num;
int C[maxn];
int lowbit(int x) { return x & -x; }
int query(int now) {
  int res = 0;
  while (now) {
    res += C[now];
    now -= lowbit(now);
  }
  return res;
}
void add(int now, int dt) {
  while (now <= num) {
    C[now] += dt;
    now += lowbit(now);
  }
}
void read() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d%d%d", &A[i].x, &A[i].r, &A[i].q);
  for (int i = 1; i <= n; i++) IQ[i] = A[i].q;
  for (int i = 1; i <= n; i++) lisan[i] = A[i].r;
}
void init() {
  sort(IQ + 1, IQ + n + 1);
  iqsz = unique(IQ + 1, IQ + n + 1) - IQ - 1;
  sort(lisan + 1, lisan + n + 1);
  num = unique(lisan + 1, lisan + n + 1) - lisan - 1;
  for (int i = 1; i <= n; i++)
    A[i].nb = lower_bound(IQ + 1, IQ + iqsz + 1, A[i].q) - IQ;
  for (int i = 1; i <= n; i++) vec[A[i].nb].push_back(A[i]);
  for (int i = 1; i <= iqsz; i++) sort(vec[i].begin(), vec[i].end(), cmp);
  for (int i = 1; i <= n; i++) {
    int z = A[i].nb;
    for (int j = z - 1; j >= max(0, z - k); j--) {
      if (A[i].q - IQ[j] <= k) {
        ff[j].push_back((edge){A[i].x - A[i].r - 1, A[i].r, -1});
        ff[j].push_back((edge){A[i].x + A[i].r, A[i].r, 1});
      }
    }
    for (int j = z + 1; j <= min(iqsz, z + k); j++) {
      if (abs(A[i].q - IQ[j]) <= k) {
        ff[j].push_back((edge){A[i].x - A[i].r - 1, A[i].r - 1, -1});
        ff[j].push_back((edge){A[i].x + A[i].r, A[i].r - 1, 1});
      }
    }
    ff[z].push_back((edge){A[i].x - A[i].r - 1, A[i].r, -1});
    ff[z].push_back((edge){A[i].x, A[i].r, 1});
    ff[z].push_back((edge){A[i].x + A[i].r, A[i].r - 1, 1});
    ff[z].push_back((edge){A[i].x, A[i].r - 1, -1});
  }
  for (int i = 1; i <= iqsz; i++) sort(ff[i].begin(), ff[i].end(), cmpp);
}
long long totans;
void work() {
  for (int i = 1; i <= iqsz; i++) {
    int pt = 0;
    for (int j = 0; j < vec[i].size(); j++) {
      vec[i][j].r =
          lower_bound(lisan + 1, lisan + num + 1, vec[i][j].r) - lisan;
      while (pt < ff[i].size() && ff[i][pt].x < vec[i][j].x) {
        ff[i][pt].r =
            upper_bound(lisan + 1, lisan + num + 1, ff[i][pt].r) - lisan - 1;
        totans += ff[i][pt].dr * (query(num) - query(ff[i][pt].r));
        pt++;
      }
      add(vec[i][j].r, 1);
    }
    while (pt < ff[i].size()) {
      ff[i][pt].r =
          upper_bound(lisan + 1, lisan + num + 1, ff[i][pt].r) - lisan - 1;
      totans += ff[i][pt].dr * (query(num) - query(ff[i][pt].r));
      pt++;
    }
    for (int j = 0; j < vec[i].size(); j++) {
      add(vec[i][j].r, -1);
    }
  }
  for (int i = 1; i <= iqsz; i++) {
    for (int j = 0; j < vec[i].size(); j++) {
      int nxt = j, hh = 1;
      while (nxt + 1 < vec[i].size() && vec[i][nxt + 1].r == vec[i][j].r &&
             vec[i][nxt + 1].x == vec[i][j].x)
        hh++, nxt++;
      totans += (1ll * hh * hh - hh) / 2;
      j = nxt;
    }
  }
  printf("%I64d\n", totans);
}
int main() {
  read();
  init();
  work();
  return 0;
}