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 = 1e5;
const int MAXX = 1e9;
struct node {
  int v, diff, h, size, cnt;
  node *lc, *rc;
  node *insert(int val);
  int lower_bound(int val);
  node *rotr();
  node *rotl();
  node *fix();
  void merge();
};
node n[MAXN + 1];
int ni;
node *ft[MAXN + 1];
int get_size(node *n) {
  if (n)
    return n->size;
  else
    return 0;
}
node *newnode(int val) {
  n[ni].v = val;
  n[ni].diff = 0;
  n[ni].h = n[ni].size = n[ni].cnt = 1;
  n[ni].lc = n[ni].rc = nullptr;
  return &n[ni++];
}
node *node::insert(int val) {
  if (this->v == val) {
    ++this->cnt;
    ++this->size;
    return this;
  }
  if (this->v < val) {
    if (this->rc)
      this->rc = this->rc->insert(val);
    else
      this->rc = newnode(val);
  } else {
    if (this->lc)
      this->lc = this->lc->insert(val);
    else
      this->lc = newnode(val);
  }
  this->merge();
  return this->fix();
}
int node::lower_bound(int val) {
  int res = get_size(this->lc) + this->cnt;
  if (this->v == val) return res;
  if (this->v < val) {
    if (this->rc) res += this->rc->lower_bound(val);
    return res;
  } else {
    if (this->lc)
      return this->lc->lower_bound(val);
    else
      return 0;
  }
}
void node::merge() {
  int l = 0, r = 0;
  if (this->lc) l = this->lc->h;
  if (this->rc) r = this->rc->h;
  this->diff = l - r;
  this->h = max(l, r) + 1;
  this->size = get_size(this->lc) + get_size(this->rc) + this->cnt;
}
node *node::rotl() {
  node *m = this->rc;
  this->rc = m->lc;
  m->lc = this;
  this->merge();
  m->merge();
  return m;
}
node *node::rotr() {
  node *m = this->lc;
  this->lc = m->rc;
  m->rc = this;
  this->merge();
  m->merge();
  return m;
}
node *node::fix() {
  if (diff < -1) {
    if (this->rc->diff > 0) this->rc = this->rc->rotr();
    return this->rotl();
  }
  if (diff > 1) {
    if (this->lc->diff < 0) this->lc = this->lc->rotl();
    return this->rotr();
  }
  return this;
}
int N, K;
int X[MAXN + 1], R[MAXN + 1], Q[MAXN + 1];
int ord[MAXN + 1];
int cQ[MAXN + 1];
int l;
bool Rcmp(const int &a, const int &b) { return R[a] > R[b]; }
int bs(int x) {
  int lb = 0, ub = N - l - 1;
  while (lb < ub) {
    int mid = (lb + ub + 1) >> 1;
    if (cQ[mid] > x)
      ub = mid - 1;
    else
      lb = mid;
  }
  return lb;
}
int query(int qi, int i) {
  if (ft[qi])
    return ft[qi]->lower_bound(X[i] + R[i]) -
           ft[qi]->lower_bound(X[i] - R[i] - 1);
  else
    return 0;
}
void insert(int qi, int i) {
  if (ft[qi])
    ft[qi] = ft[qi]->insert(X[i]);
  else
    ft[qi] = newnode(X[i]);
}
int main() {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; ++i) scanf("%d %d %d", &X[i], &R[i], &Q[i]);
  for (int i = 0; i < N; ++i) {
    ord[i] = i;
    cQ[i] = Q[i];
  }
  sort(ord, ord + N, Rcmp);
  sort(cQ, cQ + N);
  for (int i = 1; i + l < N; ++i) {
    cQ[i] = cQ[i + l];
    while (cQ[i] == cQ[i - 1] && i + l < N) cQ[i] = cQ[++l + i];
  }
  long long ans = 0LL;
  for (int i = 0; i < N; ++i) {
    int ind = ord[i];
    int qi = bs(Q[ind]);
    ans += query(qi, ind);
    for (int j = qi - 1; j >= 0 && cQ[qi] - cQ[j] <= K; --j)
      ans += query(j, ind);
    for (int j = qi + 1; j + l < N && cQ[j] - cQ[qi] <= K; ++j)
      ans += query(j, ind);
    insert(qi, ind);
  }
  printf("%lld\n", ans);
  return 0;
}