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 N = 100005;
int xx[N], x[N], idx[N], r[N], q[N], n, k, i, j, a[N], rt[N], qq[N], idq[N];
struct node {
  int l, r, s;
} t[4000000];
int tsz;
inline void ins(int& x, int l, int r, int k, int v) {
  if (!x) x = ++tsz;
  t[x].s += v;
  if (l == r) return;
  int m = (l + r) >> 1;
  if (k > m)
    ins(t[x].r, m + 1, r, k, v);
  else
    ins(t[x].l, l, m, k, v);
}
int query(int x, int rl, int rr, int l, int r) {
  if ((l == rl && r == rr) || !x) return t[x].s;
  int m = (rl + rr) >> 1;
  if (l > m)
    return query(t[x].r, m + 1, rr, l, r);
  else if (r <= m)
    return query(t[x].l, rl, m, l, r);
  else
    return query(t[x].l, rl, m, l, m) + query(t[x].r, m + 1, rr, m + 1, r);
}
bool cmp(int p, int q) { return r[p] < r[q]; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (i = 1; i <= n; ++i)
    cin >> x[i] >> r[i] >> q[i], xx[i] = x[i], a[i] = i, qq[i] = q[i];
  sort(xx + 1, xx + n + 1);
  sort(qq + 1, qq + n + 1);
  int xc = unique(xx + 1, xx + n + 1) - xx - 1,
      qc = unique(qq + 1, qq + n + 1) - qq - 1;
  long long ans = 0;
  sort(a + 1, a + n + 1, cmp);
  for (i = 1; i <= n; ++i) {
    idx[i] = lower_bound(xx + 1, xx + xc + 1, x[i]) - xx;
    idq[i] = lower_bound(qq + 1, qq + qc + 1, q[i]) - qq;
    ins(rt[idq[i]], 1, xc, idx[i], 1);
  }
  for (i = 1; i <= n; ++i) {
    int z = a[i];
    int lb = lower_bound(xx + 1, xx + xc + 1, x[z] - r[z]) - xx;
    int rb = upper_bound(xx + 1, xx + xc + 1, x[z] + r[z]) - xx - 1;
    ins(rt[idq[z]], 1, xc, idx[z], -1);
    for (j = lower_bound(qq + 1, qq + qc + 1, q[z] - k) - qq;
         j <= qc && qq[j] <= q[z] + k; ++j)
      ans += query(rt[j], 1, xc, lb, rb);
  }
  cout << ans << '\n';
  return 0;
}