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 MAXN = 100005;
long long sol;
int n, k, iq;
int p[MAXN], r[MAXN], q[MAXN];
int iq_lef[MAXN], iq_rig[MAXN], ofs[MAXN * 3];
vector<int> saz_iq, t[MAXN * 3];
vector<pair<int, int> > pos[MAXN * 3], query;
void sazmi_iq() {
  sort(saz_iq.begin(), saz_iq.end());
  saz_iq.erase(unique(saz_iq.begin(), saz_iq.end()), saz_iq.end());
  for (int i = 0; i < n; i++) {
    iq_lef[i] =
        lower_bound(saz_iq.begin(), saz_iq.end(), q[i] - k) - saz_iq.begin();
    iq_rig[i] =
        lower_bound(saz_iq.begin(), saz_iq.end(), q[i] + k) - saz_iq.begin();
    q[i] = lower_bound(saz_iq.begin(), saz_iq.end(), q[i]) - saz_iq.begin();
  }
  iq = saz_iq.size();
}
void build_tour(int ind) {
  ofs[ind] = 1;
  while (ofs[ind] < pos[ind].size()) ofs[ind] *= 2;
  for (int i = 0; i < 2 * ofs[ind]; i++) {
    t[ind].push_back(0);
  }
}
void update_tour(int ind, int pp) {
  pp += ofs[ind];
  t[ind][pp] = 1;
  pp = pp >> 1;
  while (pp) {
    t[ind][pp] = t[ind][pp * 2] + t[ind][pp * 2 + 1];
    pp = pp >> 1;
  }
}
int upit_tour(int ind, int x, int from, int to, int low, int high) {
  if (to < low || high < from) return 0;
  if (from <= low && high <= to) return t[ind][x];
  return upit_tour(ind, x * 2, from, to, low, (low + high) / 2) +
         upit_tour(ind, x * 2 + 1, from, to, (low + high) / 2 + 1, high);
}
int obradi(int x) {
  int res = 0;
  int lef = p[x] - r[x];
  int rig = p[x] + r[x];
  for (int ind = iq_lef[x]; ind <= iq_rig[x]; ind++) {
    if (pos[ind].empty()) continue;
    int tlef =
        lower_bound(pos[ind].begin(), pos[ind].end(), make_pair(lef, 0)) -
        pos[ind].begin();
    int trig =
        lower_bound(pos[ind].begin(), pos[ind].end(), make_pair(rig + 1, 0)) -
        pos[ind].begin() - 1;
    if (tlef <= trig) {
      res += upit_tour(ind, 1, tlef, trig, 0, ofs[ind] - 1);
    }
  }
  return res;
}
void update(int x) {
  int pp = lower_bound(pos[q[x]].begin(), pos[q[x]].end(), make_pair(p[x], x)) -
           pos[q[x]].begin();
  update_tour(q[x], pp);
}
void pozicije() {
  for (int i = 0; i < n; i++) {
    pos[q[i]].push_back(make_pair(p[i], i));
  }
  for (int i = 0; i < iq; i++) {
    if (pos[i].empty()) continue;
    sort(pos[i].begin(), pos[i].end());
    build_tour(i);
  }
}
void ispis() {
  cout << "---------" << endl;
  for (int i = 0; i < iq; i++) {
    if (pos[i].empty()) continue;
    cout << i << "  ";
    for (int j = 0; j < t[i].size(); j++) {
      cout << j << " " << t[i][j] << "  ";
    }
    cout << endl;
  }
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &p[i], &r[i], &q[i]);
    query.push_back(make_pair(r[i], i));
    saz_iq.push_back(q[i]);
    saz_iq.push_back(q[i] + k);
    saz_iq.push_back(q[i] - k);
  }
  sazmi_iq();
  pozicije();
  sort(query.begin(), query.end());
  for (int i = query.size() - 1; i >= 0; i--) {
    int x = query[i].second;
    sol += obradi(x);
    update(x);
  }
  cout << sol << endl;
  return 0;
}