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>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
const int N = 100005;
int n, k;
struct abc {
  int x, ra, q;
} p[N], tmp[N];
long long ans;
set<int> s;
map<int, int> mp;
int cnt;
bool operator<(abc a, abc b) {
  if (a.ra == b.ra && a.x == b.x) return a.q < b.q;
  if (a.ra == b.ra) return a.x < b.x;
  return a.ra > b.ra;
}
int c[N];
int lowbit(int x) { return x & (-x); }
void modify(int i, int x) {
  while (i <= 100000) c[i] += x, i += lowbit(i);
}
int query(int i) {
  if (i == 0) return 0;
  int sum = 0;
  while (i) sum += c[i], i -= lowbit(i);
  return sum;
}
void solve(int l, int r) {
  if (l >= r) return;
  int mid = (l + r) / 2;
  solve(l, mid);
  solve(mid + 1, r);
  int h = l, t = l - 1;
  for (int i = mid + 1; i <= r; i++) {
    while (p[t + 1].q <= p[i].q + k && t + 1 <= mid) {
      t++;
      modify(mp[p[t].x], 1);
    }
    while (p[h].q < p[i].q - k && h <= t) {
      modify(mp[p[h].x], -1);
      h++;
    }
    int aa = mp[*s.upper_bound(p[i].x + p[i].ra)] - 1;
    int bb = mp[*s.lower_bound(max(1, p[i].x - p[i].ra))] - 1;
    ans += query(aa) - query(bb);
  }
  while (h <= t) modify(mp[p[h].x], -1), h++;
  int xx = l, y = mid + 1, cnt = l;
  while (xx <= mid && y <= r) {
    if (p[xx].q <= p[y].q)
      tmp[cnt++] = p[xx++];
    else
      tmp[cnt++] = p[y++];
  }
  while (xx <= mid) tmp[cnt++] = p[xx++];
  while (y <= r) tmp[cnt++] = p[y++];
  for (int i = l; i <= r; i++) p[i] = tmp[i];
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &p[i].x, &p[i].ra, &p[i].q);
    p[i].x++;
    s.insert(p[i].x);
  }
  s.insert(2 * 1e9 + 1);
  set<int>::iterator it = s.begin();
  for (; it != s.end(); it++) {
    if (!mp[*it]) {
      mp[*it] = ++cnt;
    }
  }
  sort(p + 1, p + n + 1);
  solve(1, n);
  cout << ans;
}