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 = 1e5 + 10, M = 1e3 + 10, MOD = 1e9 + 7;
int n, k, pos, ri, qi, cntr = 1, reall[N];
long long int res;
map<int, int> IQmp;
vector<int> q;
vector<pair<pair<int, int>, int> > r, p;
vector<vector<int> > iqtopos, seg;
void update(int pos, int l, int r, int idx, int ind) {
  if (l == r) {
    seg[ind][pos]++;
    return;
  }
  int mid = (l + r) >> 1;
  if (idx <= mid)
    update(pos << 1, l, mid, idx, ind);
  else
    update((pos << 1) + 1, mid + 1, r, idx, ind);
  seg[ind][pos] = seg[ind][pos << 1] + seg[ind][(pos << 1) + 1];
}
int query(int pos, int l, int r, int nl, int nr, int ind) {
  if (l > r || l > nr || r < nl) {
    return 0;
  }
  if (l >= nl && r <= nr) {
    return seg[ind][pos];
  }
  return query(pos << 1, l, (l + r) >> 1, nl, nr, ind) +
         query((pos << 1) + 1, ((l + r) >> 1) + 1, r, nl, nr, ind);
}
int main() {
  scanf("%d%d", &n, &k);
  seg.resize(N);
  iqtopos.resize(N);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &pos, &ri, &qi);
    r.push_back(make_pair(make_pair(ri, pos), qi));
    p.push_back(make_pair(make_pair(pos, ri), qi));
    q.push_back(qi);
  }
  sort(r.begin(), r.end());
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  for (int i = 0; i < n; i++) {
    if (!IQmp[q[i]]) {
      IQmp[q[i]] = cntr;
      reall[cntr] = q[i];
      cntr++;
    }
  }
  for (int i = 0; i < n; i++) {
    iqtopos[IQmp[p[i].second]].push_back(p[i].first.first);
  }
  for (int i = 0; i < n; i++) {
    seg[i + 1].resize(4 * (iqtopos[i + 1].size() + 1));
  }
  for (int i = 0; i < n; i++) {
    int rr = r[i].first.first;
    int pp = r[i].first.second;
    int qq = r[i].second;
    int ind = IQmp[qq];
    vector<int>::iterator it1, it2;
    int indx = lower_bound(iqtopos[ind].begin(), iqtopos[ind].end(), pp) -
               iqtopos[ind].begin();
    update(1, 0, iqtopos[ind].size() - 1, indx, ind);
    it1 = lower_bound(iqtopos[ind].begin(), iqtopos[ind].end(), pp - rr);
    it2 = upper_bound(iqtopos[ind].begin(), iqtopos[ind].end(), pp + rr);
    it2--;
    int ind1 = it1 - iqtopos[ind].begin();
    int ind2 = it2 - iqtopos[ind].begin();
    if (ind1 < iqtopos[ind].size() && iqtopos[ind][ind1] <= pp + rr) {
      res += ind2 - ind1 + 1 -
             query(1, 0, iqtopos[ind].size() - 1, ind1, ind2, ind);
    }
    int kkk = ind;
    for (int i = 1; i <= k; i++) {
      if (reall[i + kkk] == 0 || reall[i + kkk] > k + qq) break;
      int ind = i + kkk;
      it1 = lower_bound(iqtopos[ind].begin(), iqtopos[ind].end(), pp - rr);
      it2 = upper_bound(iqtopos[ind].begin(), iqtopos[ind].end(), pp + rr);
      it2--;
      int ind1 = it1 - iqtopos[ind].begin();
      int ind2 = it2 - iqtopos[ind].begin();
      if (ind1 < iqtopos[ind].size() && iqtopos[ind][ind1] <= pp + rr) {
        res += ind2 - ind1 + 1 -
               query(1, 0, iqtopos[ind].size() - 1, ind1, ind2, ind);
      }
    }
    kkk = ind;
    for (int i = 1; i <= k; i++) {
      if (kkk - i == 0 || reall[kkk - i] + k < qq) break;
      int ind = kkk - i;
      it1 = lower_bound(iqtopos[ind].begin(), iqtopos[ind].end(), pp - rr);
      it2 = upper_bound(iqtopos[ind].begin(), iqtopos[ind].end(), pp + rr);
      it2--;
      int ind1 = it1 - iqtopos[ind].begin();
      int ind2 = it2 - iqtopos[ind].begin();
      if (ind1 < iqtopos[ind].size() && iqtopos[ind][ind1] <= pp + rr) {
        res += ind2 - ind1 + 1 -
               query(1, 0, iqtopos[ind].size() - 1, ind1, ind2, ind);
      }
    }
  }
  cout << res;
  return 0;
}