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 inf = 1e9 + 25;
map<int, int> mp;
int num = 0;
int tim = 0, vis[100010];
int n, k, N = 0;
struct node {
  int a, num, op;
} b[500010];
struct point {
  int l, x, r, s;
} a[100010];
struct trnode {
  int lc, rc, c;
} tr[6000010];
int tot = 0, root[100010];
struct query {
  int op, x, l, r, y;
} q[500010];
void update(int &x, int l, int r, int k) {
  if (!x) x = ++tot;
  if (l == r) {
    tr[x].c++;
    return;
  }
  int mid = (l + r) / 2;
  if (k <= mid)
    update(tr[x].lc, l, mid, k);
  else
    update(tr[x].rc, mid + 1, r, k);
  tr[x].c = tr[tr[x].lc].c + tr[tr[x].rc].c;
}
int findans(int x, int l, int r, int fl, int fr) {
  if (!x) return 0;
  if (l == fl && r == fr) return tr[x].c;
  int mid = (l + r) / 2;
  if (fr <= mid) return findans(tr[x].lc, l, mid, fl, fr);
  if (fl > mid) return findans(tr[x].rc, mid + 1, r, fl, fr);
  return findans(tr[x].lc, l, mid, fl, mid) +
         findans(tr[x].rc, mid + 1, r, mid + 1, fr);
}
bool cmp(node a, node b) { return a.a < b.a; }
bool cmp1(query a, query b) { return a.x == b.x ? a.op > b.op : a.x < b.x; }
bool cmp3(point a, point b) { return a.x < b.x; }
long long ans = 0;
void solve(int l, int r) {
  tim++;
  for (int i = l; i <= r; i++) {
    int c = mp[a[i].s];
    if (vis[c] != tim) vis[c] = tim, root[c] = 0;
    root[c]++;
  }
  int re = 0;
  for (int i = l; i <= r; i++)
    for (int j = a[i].s - k; j <= a[i].s + k; j++)
      if (mp[j] && vis[mp[j]] == tim) re += root[mp[j]];
  ans = ans - (re - (r - l + 1)) / 2 - (r - l + 1);
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", &a[i].x, &a[i].l, &a[i].s);
    int t = a[i].l;
    a[i].l = max(0, a[i].x - t);
    a[i].r = a[i].x + t;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    b[++cnt].num = i;
    b[cnt].op = 1;
    b[cnt].a = a[i].l;
    b[++cnt].num = i;
    b[cnt].op = 2;
    b[cnt].a = a[i].x;
    b[++cnt].num = i;
    b[cnt].op = 3;
    b[cnt].a = a[i].r;
  }
  sort(b + 1, b + cnt + 1, cmp);
  for (int i = 1; i <= cnt; i++) {
    if (i == 1 || b[i].a != b[i - 1].a) N++;
    if (b[i].op == 1) a[b[i].num].l = N;
    if (b[i].op == 2) a[b[i].num].x = N;
    if (b[i].op == 3) a[b[i].num].r = N;
  }
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    q[++cnt].op = 1;
    q[cnt].x = a[i].x;
    q[cnt].l = a[i].s - k;
    q[cnt].r = a[i].s + k;
    q[cnt].y = a[i].x;
    q[++cnt].op = 2;
    q[cnt].x = a[i].l - 1;
    q[cnt].l = a[i].s - k;
    q[cnt].r = a[i].s + k;
    q[cnt].y = a[i].x;
    q[++cnt].op = 3;
    q[cnt].x = a[i].x;
    q[cnt].l = a[i].s;
    q[cnt].r = a[i].r;
  }
  sort(q + 1, q + cnt + 1, cmp1);
  for (int i = 1; i <= cnt; i++) {
    if (q[i].op == 3) {
      int c = q[i].l;
      if (!mp[c]) mp[c] = ++num;
      update(root[mp[c]], 1, N, q[i].r);
    } else {
      int t = 0;
      for (int j = q[i].l; j <= q[i].r; j++) {
        if (!mp[j]) continue;
        t += findans(root[mp[j]], 1, N, q[i].y, N);
      }
      if (q[i].op == 1)
        ans += t;
      else
        ans -= t;
    }
  }
  memset(root, 0, sizeof(root));
  sort(a + 1, a + n + 1, cmp3);
  int l = 1;
  for (int i = 1; i <= n; i++) {
    if (i == 1 || a[i].x == a[i - 1].x)
      continue;
    else
      solve(l, i - 1), l = i;
  }
  solve(l, n);
  printf("%lld\n", ans);
}