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;
struct pp {
  int x, r, iq, rk, id;
} rob[100005];
struct uu {
  int r, id;
  bool operator<(const uu& y) const { return r > y.r; }
} hh;
struct inter {
  int x, id;
  bool operator<(const inter& y) const {
    return x < y.x || (x == y.x && id < y.id);
  }
} h;
set<inter> s[100005];
set<inter>::iterator it;
priority_queue<uu> q;
int n, i, j, k, pre = -1, id, hd[100005], tl[100005], nu[100005], tr[100005],
                cnt;
long long ans = 0;
int lowbit(int p) { return p & -p; }
void add(int p, int v) {
  while (p <= n) {
    tr[p] += v;
    p += lowbit(p);
  }
}
int ask(int p) {
  int ans = 0;
  while (p) {
    ans += tr[p];
    p -= lowbit(p);
  }
  return ans;
}
bool cmp(pp a, pp b) { return a.iq < b.iq || (a.iq == b.iq && a.x < b.x); }
bool cmp2(pp a, pp b) { return a.x < b.x; }
int main() {
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++) scanf("%d%d%d", &rob[i].x, &rob[i].r, &rob[i].iq);
  sort(rob + 1, rob + n + 1, cmp);
  for (i = 1; i <= n; i++) {
    rob[i].id = rob[i - 1].id + 1;
    rob[i].rk = rob[i].iq == pre ? rob[i - 1].rk : (rob[i - 1].rk + 1);
    pre = rob[i].iq;
    nu[rob[i].rk] = rob[i].iq;
    if (!hd[rob[i].rk]) hd[rob[i].rk] = i;
    tl[rob[i].rk] = i;
  }
  cnt = rob[n].rk;
  sort(rob + 1, rob + n + 1, cmp2);
  for (i = 1; i <= n; i++) {
    while (!q.empty() && q.top().r < rob[i].x) {
      hh = q.top();
      q.pop();
      s[rob[hh.id].rk].erase((inter){rob[hh.id].x, rob[hh.id].id});
      id = rob[hh.id].id;
      add(id, -1);
      add(tl[rob[hh.id].rk] + 1, 1);
    }
    for (j = rob[i].rk; j > 0 && nu[j] >= rob[i].iq - k; j--) {
      it = s[j].lower_bound((inter){rob[i].x - rob[i].r, 0});
      if (it != s[j].end()) ans += s[j].size() - ask((*it).id) + 1;
    }
    for (j = rob[i].rk + 1; j <= cnt && nu[j] <= rob[i].iq + k; j++) {
      it = s[j].lower_bound((inter){rob[i].x - rob[i].r, 0});
      if (it != s[j].end()) ans += s[j].size() - ask((*it).id) + 1;
    }
    q.push((uu){rob[i].x + rob[i].r, i});
    s[rob[i].rk].insert((inter){rob[i].x, rob[i].id});
    add(rob[i].id, 1);
    add(tl[rob[i].rk] + 1, -1);
  }
  printf("%I64d\n", ans);
  return 0;
}