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;
int x[101010], r[101010], q[101010], n, K, m, le[101010], ri[101010];
map<int, int> mp;
vector<int> v[101010];
int qs[101010];
bool cmp(int i, int j) { return r[i] > r[j]; }
struct Fenwick_Tree {
  int f[101010];
  int sum(int x) {
    if (!x) return 0;
    int rlt = 0;
    for (int k = x; k; k -= k & -k) rlt += f[k];
    return rlt;
  }
  int query(int le, int ri) { return sum(ri) - sum(le - 1); }
  void modify(int x) {
    for (int k = x; k <= m; k += k & -k) f[k]++;
  }
  void erase(int x) {
    for (int k = x; k <= m; k += k & -k) f[k]--;
  }
} T1, T2;
long long solve_1(vector<int> &v) {
  int p = v.size();
  long long rlt = 0;
  for (int i = 0; i < p; i++) {
    rlt += T1.query(le[v[i]], ri[v[i]]);
    T1.modify(x[v[i]]);
  }
  for (int i = 0; i < p; i++) T1.erase(x[v[i]]);
  return rlt;
}
long long solve_2(vector<int> &v, vector<int> &u) {
  int i = 0, j = 0;
  int p = v.size(), q = u.size();
  long long rlt = 0;
  while (i < p || j < q) {
    if (i == p) {
      rlt += T1.query(le[u[j]], ri[u[j]]);
      T2.modify(x[u[j++]]);
      continue;
    }
    if (j == q) {
      rlt += T2.query(le[v[i]], ri[v[i]]);
      T1.modify(x[v[i++]]);
      continue;
    }
    if (r[u[j]] > r[v[i]]) {
      rlt += T1.query(le[u[j]], ri[u[j]]);
      T2.modify(x[u[j++]]);
    } else {
      rlt += T2.query(le[v[i]], ri[v[i]]);
      T1.modify(x[v[i++]]);
    }
  }
  for (i = 0; i < p; i++) T1.erase(x[v[i]]);
  for (j = 0; j < q; j++) T2.erase(x[u[j]]);
  return rlt;
}
int xs[101010];
int main() {
  scanf("%d %d", &n, &K);
  m = 0;
  xs[++m] = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d %d %d", &x[i], &r[i], &q[i]), xs[++m] = x[i];
  sort(xs + 1, xs + m + 1);
  int mm = 0;
  for (int i = 1; i <= m; i++)
    if (i == 1 || xs[i] > xs[i - 1]) xs[++mm] = xs[i];
  m = mm;
  for (int i = 1; i <= n; i++) {
    le[i] = lower_bound(xs + 1, xs + m + 1, x[i] - r[i]) - xs;
    ri[i] = lower_bound(xs + 1, xs + m + 1, x[i] + r[i] + 1) - xs - 1;
    x[i] = lower_bound(xs + 1, xs + m + 1, x[i]) - xs;
  }
  int e = 0;
  for (int i = 1; i <= n; i++) {
    if (!mp.count(q[i])) mp[q[i]] = ++e, qs[e] = q[i];
    v[mp[q[i]]].push_back(i);
  }
  for (int i = 1; i <= e; i++) sort(v[i].begin(), v[i].end(), cmp);
  long long ans = 0;
  for (int i = 1; i <= e; i++) {
    ans += solve_1(v[i]);
    for (int k = 1; k <= K; k++)
      if (mp.count(qs[i] + k)) {
        int j = mp[qs[i] + k];
        ans += solve_2(v[i], v[j]);
      }
  }
  printf("%I64d\n", ans);
  return 0;
}