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;
class Timer {
 private:
  string scope_name;
  chrono::high_resolution_clock::time_point start_time;

 public:
  Timer(string name) : scope_name(name) {
    start_time = chrono::high_resolution_clock::now();
  }
  ~Timer() {
    auto stop_time = chrono::high_resolution_clock::now();
    auto length =
        chrono::duration_cast<chrono::microseconds>(stop_time - start_time)
            .count();
    double mlength = double(length) * 0.001;
    ;
  }
};
const long long MOD = 1000000007;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const long long MAXN = 100005;
struct Robot {
  int x, r, q, qid;
} rbt[MAXN];
int n, k;
long long ans;
vector<int> qval;
struct Treap {
  struct Node {
    Node *l, *r;
    int pri, sz;
    pair<int, int> key;
    Node(int x, int id) {
      l = r = nullptr;
      pri = rand();
      sz = 1;
      key = pair<int, int>(x, id);
    }
    void pull() {
      sz = 1;
      if (l) {
        sz += l->sz;
      }
      if (r) {
        sz += r->sz;
      }
    }
  };
  Node *root;
  int SIZ(Node *a) { return a ? a->sz : 0; }
  Node *mrg(Node *a, Node *b) {
    if (!a || !b) {
      return a ? a : b;
    }
    if (a->pri > b->pri) {
      a->r = mrg(a->r, b);
      a->pull();
      return a;
    } else {
      b->l = mrg(a, b->l);
      b->pull();
      return b;
    }
  }
  void split(Node *o, Node *&a, Node *&b, pair<int, int> sp) {
    if (!o) {
      a = b = nullptr;
      return;
    } else {
      if (o->key >= sp) {
        b = o;
        split(b->l, a, b->l, sp);
      } else {
        a = o;
        split(a->r, a->r, b, sp);
      }
      o->pull();
    }
  }
  void era(int x, int id) {
    Node *l, *m, *r;
    split(root, l, m, pair<int, int>(x, id));
    split(m, m, r, pair<int, int>(x, id + 1));
    root = mrg(l, r);
    if (m) {
      delete m;
    }
  }
  void ins(int x, int id) {
    Node *nw = new Node(x, id);
    if (!root) {
      root = nw;
    } else {
      Node *l, *r;
      split(root, l, r, pair<int, int>(x, id));
      root = mrg(l, mrg(nw, r));
    }
  }
  int qry(int l, int r) {
    Node *L, *M, *R;
    split(root, L, M, pair<int, int>(l, -iNF));
    split(M, M, R, pair<int, int>(r + 1, -iNF));
    int ret = SIZ(M);
    root = mrg(L, mrg(M, R));
    return ret;
  }
} trp[MAXN];
int main() {
  ;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i += 1) {
    cin >> rbt[i].x >> rbt[i].r >> rbt[i].q;
    qval.emplace_back(rbt[i].q);
  }
  sort(qval.begin(), qval.end());
  qval.resize(unique(qval.begin(), qval.end()) - qval.begin());
  for (int i = 0; i < n; i += 1) {
    rbt[i].qid = lower_bound(qval.begin(), qval.end(), rbt[i].q) - qval.begin();
  }
  sort(rbt, rbt + n, [&](Robot r1, Robot r2) { return r1.x < r2.x; });
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  for (int i = 0; i < n; i += 1) {
    ;
    int x = rbt[i].x, r = rbt[i].r, q = rbt[i].q, qid = rbt[i].qid;
    while (!pq.empty() && pq.top().first < x) {
      int id = pq.top().second;
      trp[rbt[id].qid].era(rbt[id].x, id);
      pq.pop();
    }
    int ptr = qid;
    while (ptr > 0 && q - qval[ptr - 1] <= k) {
      ptr--;
    }
    while (ptr < int(qval.size()) && abs(q - qval[ptr]) <= k) {
      ans += trp[ptr].qry(x - r, x + r);
      ptr++;
    }
    pq.emplace(x + r, i);
    trp[qid].ins(x, i);
  }
  cout << ans << '\n';
  return 0;
}