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;
bool comp(array<int, 3> a, array<int, 3> b) { return a[1] > b[1]; }
const int SZ = (1 << 30);
template <class T>
struct node {
  vector<array<int, 2>> c;
  vector<int> val;
  int cur;
  node() {
    c.push_back({-1, -1});
    cur = 1;
    val.push_back(0);
  }
  void upd(int nd, int ind, T v, int L = 0, int R = SZ - 1) {
    if (L == ind && R == ind) {
      val[nd] += v;
      return;
    }
    int M = (L + R) / 2;
    if (ind <= M) {
      if (c[nd][0] == -1) {
        c[nd][0] = cur++;
        c.push_back({-1, -1});
        val.push_back(0);
      }
      upd(c[nd][0], ind, v, L, M);
    } else {
      if (c[nd][1] == -1) {
        c[nd][1] = cur++;
        c.push_back({-1, -1});
        val.push_back(0);
      }
      upd(c[nd][1], ind, v, M + 1, R);
    }
    val[nd] = 0;
    for (int i = 0; i < 2; ++i)
      if (c[nd][i] != -1) val[nd] += val[c[nd][i]];
  }
  T query(int nd, int lo, int hi, int L = 0, int R = SZ - 1) {
    if (hi < L || R < lo) return 0;
    if (lo <= L && R <= hi) return val[nd];
    int M = (L + R) / 2;
    T res = 0;
    if (c[nd][0] != -1) res += query(c[nd][0], lo, hi, L, M);
    if (c[nd][1] != -1) res += query(c[nd][1], lo, hi, M + 1, R);
    return res;
  }
};
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<array<int, 3>> a(n);
  for (int i = 0; i < n; ++i) {
    int x, r, q;
    cin >> x >> r >> q;
    a[i] = {x, r, q};
  }
  sort((a).begin(), (a).end(), comp);
  map<int, int> exist;
  map<int, node<int>> segs;
  long long ans = 0;
  for (auto [x, r, q] : a) {
    for (int i = q - k; i <= q + k; ++i) {
      if (!exist[i]) continue;
      ans += segs[i].query(0, max(x - r, 0), x + r);
    }
    if (!exist[q]) {
      segs[q] = node<int>();
    }
    segs[q].upd(0, x, 1);
    exist[q] = 1;
  }
  cout << ans << "\n";
}