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 long long N = 100005;
long long n, k;
struct abc {
  long long x, ra, q;
} p[N], tmp[N];
long long ans;
set<long long> s;
map<long long, long long> mp;
long long 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;
}
long long c[N];
long long lowbit(long long x) { return x & (-x); }
void modify(long long i, long long x) {
  while (i <= 100000) c[i] += x, i += lowbit(i);
}
long long query(long long i) {
  if (i == 0) return 0;
  long long sum = 0;
  while (i) sum += c[i], i -= lowbit(i);
  return sum;
}
void solve(long long l, long long r) {
  if (l >= r) return;
  long long mid = (l + r) / 2;
  solve(l, mid);
  solve(mid + 1, r);
  long long h = l, t = l - 1;
  for (long long 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++;
    }
    long long aa = mp[*s.upper_bound(p[i].x + p[i].ra)] - 1;
    long long bb = mp[*s.lower_bound(max(1LL, p[i].x - p[i].ra))] - 1;
    ans += query(aa) - query(bb);
  }
  while (h <= t) modify(mp[p[h].x], -1), h++;
  long long 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 (long long i = l; i <= r; i++) p[i] = tmp[i];
}
int main() {
  scanf("%lld%lld", &n, &k);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld%lld%lld", &p[i].x, &p[i].ra, &p[i].q);
    p[i].x++;
    s.insert(p[i].x);
  }
  s.insert(2 * 1e9 + 1);
  set<long long>::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;
}