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 N;
vector<int> x, r;
void UpdateFw(vector<int> &fw, int x, int diff) {
  int MAXX = fw.size() - 1;
  for (int i = x; i <= MAXX; i += i & -i) {
    fw[i] += diff;
    if (i > (MAXX - (i & -i))) {
      break;
    }
  }
}
int64_t SumFw(const vector<int> &fw, int x) {
  int64_t res = 0;
  for (int i = x; i > 0; i -= i & -i) {
    res += fw[i];
  }
  return res;
}
int64_t QueryFw(const vector<int> &fw, int xmin, int xmax) {
  if (xmax < xmin) {
    return 0;
  }
  return SumFw(fw, xmax) - SumFw(fw, xmin - 1);
}
bool IsLess(const int i, const int j) {
  int pi = i % N, pj = j % N;
  int ti = i / N, tj = j / N;
  int vi = x[pi], vj = x[pj];
  if (ti == 0) {
    vi -= r[pi];
  } else if (ti == 2) {
    vi += r[pi];
  }
  if (tj == 0) {
    vj -= r[pj];
  } else if (tj == 2) {
    vj += r[pj];
  }
  if (vi != vj) {
    return vi < vj;
  } else {
    return ti < tj;
  }
}
void CalcRank(const vector<int> &a, vector<int> &id2rank,
              vector<int> &rank2id) {
  int n = a.size();
  vector<pair<int, int> > b(n);
  for (int i = 0; i < n; i++) {
    b[i] = make_pair(a[i], i);
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < n; i++) {
    id2rank[b[i].second] = i;
    rank2id[i] = b[i].second;
  }
  return;
}
int main(int argc, char **argv) {
  int K;
  scanf("%d%d", &N, &K);
  const int NMAX = 1e5l;
  vector<int> q(N);
  x.resize(N);
  r.resize(N);
  for (int i = 0; i < N; i++) {
    scanf("%d%d%d", &x[i], &r[i], &q[i]);
  }
  map<int, vector<int> > gqx, gqxid;
  vector<int> xid2qxrnk(N);
  for (int i = 0; i < N; i++) {
    gqx[q[i]].push_back(x[i]);
    gqxid[q[i]].push_back(i);
  }
  map<int, vector<int> > fw;
  for (map<int, vector<int> >::iterator it = gqx.begin(), iti = gqxid.begin();
       it != gqx.end(); it++, iti++) {
    vector<int> &qx = it->second;
    int qrank = it->first;
    vector<int> &qxid = iti->second;
    int m = qx.size();
    vector<int> gqrnk2id(m), gqid2rnk(m);
    CalcRank(qx, gqid2rnk, gqrnk2id);
    for (int j = 0; j < m; j++) {
      xid2qxrnk[qxid[j]] = gqid2rnk[j];
    }
    sort(qx.begin(), qx.end());
    fw[qrank] = vector<int>(m + 1, 0);
  }
  gqxid.clear();
  vector<int> id(3 * N);
  for (int i = 0; i < N; i++) {
    id[i] = i;
    id[N + i] = N + i;
    id[N + N + i] = N + N + i;
  }
  sort(id.begin(), id.end(), IsLess);
  int64_t res = 0;
  for (int i = 0; i < 3 * N; i++) {
    int ti = id[i] / N;
    int bi = id[i] % N;
    int xi = x[bi], ri = r[bi], qi = q[bi];
    int xpos = xid2qxrnk[bi] + 1;
    if (ti == 0) {
      UpdateFw(fw[qi], xpos, 1);
    } else if (ti == 1) {
      int qkmin = max(0, qi - K), qkmax = min(qi + K, 1000000000);
      for (int qj = qkmin; qj <= qkmax; qj++) {
        if (gqx.count(qj) == 0) {
          continue;
        }
        const vector<int> &qx = gqx.at(qj);
        if (qx.empty()) {
          continue;
        }
        int xmin = max(0, xi - ri);
        int xmax = min(xi + ri, 1000000000);
        int xminpos = lower_bound(qx.begin(), qx.end(), xmin) - qx.begin();
        int xmaxpos = upper_bound(qx.begin(), qx.end(), xmax) - qx.begin() - 1;
        if (xminpos > xmaxpos) {
          continue;
        }
        res += QueryFw(fw.at(qj), xminpos + 1, xmaxpos + 1);
      }
    } else {
      UpdateFw(fw[qi], xpos, -1);
    }
  }
  res -= N;
  res >>= 1;
  printf("%" PRId64 "\n", res);
  return 0;
}