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;
using namespace rel_ops;
using ll = int64_t;
using Pii = pair<int, int>;
using ull = uint64_t;
using Vi = vector<int>;
void run();
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  run();
  return 0;
}
int uplg(int n) { return 32 - __builtin_clz(n); }
int uplg(ll n) { return 64 - __builtin_clzll(n); }
int cmp(double a, double b, double eps = 1e-9) {
  return (a > b + eps) - (a + eps < b);
}
struct Elem {
  int first, r, q;
  int compX;
};
struct Fenwick {
  using T = int;
  const T ID = 0;
  T f(T a, T b) { return a + b; }
  vector<T> s;
  Fenwick(int n = 0) { init(n); }
  void init(int n) { s.assign(n, ID); }
  void modify(int i, T v) {
    for (; i < int((s).size()); i |= i + 1) s[i] = f(s[i], v);
  }
  T query(int i) {
    T v = ID;
    for (; i > 0; i &= i - 1) v = f(v, s[i - 1]);
    return v;
  }
};
int n, k;
vector<Elem> elems;
Fenwick tree;
int compressVec(vector<int*>& vec) {
  sort((vec).begin(), (vec).end(), [](int* l, int* r) { return *l < *r; });
  int last = *vec[0], i = 0;
  for (auto& e : (vec)) {
    if (*e != last) i++;
    last = *e;
    *e = i;
  }
  return i + 1;
}
void run() {
  cin >> n >> k;
  elems.resize(n);
  for (auto& e : (elems)) cin >> e.first >> e.r >> e.q;
  vector<int*> toComp;
  for (auto& e : (elems)) {
    e.compX = e.first;
    toComp.push_back(&e.compX);
  }
  tree.init(compressVec(toComp));
  sort((elems).begin(), (elems).end(),
       [](Elem l, Elem r) { return l.q < r.q; });
  Vi sortedByX(n);
  iota((sortedByX).begin(), (sortedByX).end(), 0);
  sort((sortedByX).begin(), (sortedByX).end(),
       [](int l, int r) { return elems[l].first < elems[r].first; });
  int iqBegin = 0, iqEnd = 0;
  ll ans = 0;
  int iq = -1, iqPos = 0;
  while (true) {
    while (iqPos < int((elems).size()) && elems[iqPos].q == iq) iqPos++;
    if (iqPos >= int((elems).size())) break;
    iq = elems[iqPos].q;
    while (iqEnd < int((elems).size()) && elems[iqEnd].q <= iq + k) {
      iqEnd++;
    }
    while (iqBegin < iqEnd && elems[iqBegin].q < iq - k) {
      iqBegin++;
    }
    vector<Pii> events;
    for (int i = (iqBegin); i < (iqEnd); i++) {
      events.push_back({elems[i].first, i + 1});
      events.push_back({elems[i].first + elems[i].r + 1, -i - 1});
    }
    sort((events).begin(), (events).end());
    for (auto& evt : (events)) {
      int i = abs(evt.second) - 1;
      auto& e = elems[i];
      tree.modify(e.compX, evt.second < 0 ? -1 : 1);
      if (evt.second > 0 && e.q == iq) {
        int from =
            *lower_bound((sortedByX).begin(), (sortedByX).end(), e.first - e.r,
                         [](int l, int r) { return elems[l].first < r; });
        ans += tree.query(e.compX + 1) - tree.query(elems[from].compX) - 1;
      }
    }
  }
  cout << ans << endl;
}