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;
mt19937 rnd(42);
struct Treap {
  Treap *l, *r;
  int x, y;
  int sz;
  Treap(int x) : l(nullptr), r(nullptr), x(x), y(rnd()), sz(1) {}
  Treap() {}
};
typedef Treap *pTreap;
Treap treaps[1000000];
pTreap curTreap = treaps;
inline pTreap newTreap(int x) {
  pTreap res = curTreap++;
  *res = Treap(x);
  return res;
}
inline int getSz(pTreap t) { return t ? t->sz : 0; }
inline void update(pTreap t) {
  if (t) {
    t->sz = getSz(t->l) + 1 + getSz(t->r);
  }
}
inline void split(pTreap t, pTreap &l, pTreap &r, int x) {
  if (!t) {
    l = r = nullptr;
  } else {
    if (t->x >= x) {
      split(t->l, l, t->l, x);
      r = t;
    } else {
      split(t->r, t->r, r, x);
      l = t;
    }
    update(l);
    update(r);
  }
}
inline void merge(pTreap &t, pTreap l, pTreap r) {
  if (!l || !r) {
    t = l ? l : r;
  } else {
    if (l->y > r->y) {
      merge(l->r, l->r, r);
      t = l;
    } else {
      merge(r->l, l, r->l);
      t = r;
    }
    update(t);
  }
}
inline void insert(pTreap &t, int x) {
  pTreap l, r;
  split(t, l, r, x);
  merge(l, l, newTreap(x));
  merge(t, l, r);
}
inline void erase(pTreap &t, int x) {
  if (t) {
    if (t->x == x) {
      merge(t, t->l, t->r);
    } else {
      erase(x < t->x ? t->l : t->r, x);
    }
    update(t);
  }
}
inline int ranged(pTreap &t, int al, int ar) {
  pTreap l, m, r;
  split(t, l, m, al);
  split(m, m, r, ar + 1);
  int res = getSz(m);
  merge(m, m, r);
  merge(t, l, m);
  return res;
}
struct Robot {
  int x, r, q;
};
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  map<int, pTreap> robotsByIq;
  vector<Robot> v(n);
  vector<tuple<int, int, int> > events;
  for (int i = 0; i < n; i++) {
    Robot ro;
    cin >> ro.x >> ro.r >> ro.q;
    events.emplace_back(ro.x - ro.r, -1, i);
    events.emplace_back(ro.x, 0, i);
    events.emplace_back(ro.x + ro.r, +1, i);
    v[i] = ro;
  }
  sort(events.begin(), events.end());
  long long ans = 0;
  for (auto evt : events) {
    int qid = get<1>(evt), idx = get<2>(evt);
    Robot ro = v[idx];
    if (qid < 0) {
      insert(robotsByIq[ro.q], ro.x);
    } else if (qid == 0) {
      for (int i = ro.q - k; i <= ro.q + k; i++) {
        if (robotsByIq.count(i)) {
          ans += ranged(robotsByIq[i], ro.x - ro.r, ro.x + ro.r);
        }
      }
      ans--;
    } else {
      erase(robotsByIq[ro.q], ro.x);
    }
  }
  assert(ans % 2 == 0);
  cout << ans / 2 << endl;
  return 0;
}