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;
template <typename T>
struct Treap {
  struct Node {
    T val, sum;
    int pri, cnt;
    Node *lch, *rch;
    Node(T v) : val(v), pri(rnd()), cnt(1), sum(v) { lch = rch = nullptr; }
  };
  Node* node;
  Treap(Node* n = nullptr) { node = n; }
  Treap(T v) { node = new Node(v); }
  void initialize(T v) { node = new Node(v); }
  int count(Node* t) { return !t ? 0 : t->cnt; }
  T sum(Node* t) { return !t ? 0 : t->sum; }
  int count() { return count(node); }
  T sum() { return sum(node); }
  Node* update(Node* t) {
    t->cnt = count(t->lch) + count(t->rch) + 1;
    t->sum = sum(t->lch) + sum(t->rch) + t->val;
    return t;
  }
  Node* merge(Node* l, Node* r) {
    if (!l || !r) return !l ? r : l;
    if (l->val > r->val) swap(l, r);
    if (l->pri > r->pri) {
      l->rch = merge(l->rch, r);
      return update(l);
    } else {
      r->lch = merge(l, r->lch);
      return update(r);
    }
  }
  void merge(Treap* tr) { node = merge(tr->node); }
  pair<Node*, Node*> split(Node* t, T v) {
    if (!t) return make_pair(nullptr, nullptr);
    if (v < t->val) {
      auto s = split(t->lch, v);
      t->lch = s.second;
      return {s.first, update(t)};
    } else {
      auto s = split(t->rch, v);
      t->rch = s.first;
      return {update(t), s.second};
    }
  }
  pair<Treap*, Treap*> split(T v) {
    auto p = split(node, v);
    node = p.first;
    auto t2 = new Treap(p.second);
    return make_pair(this, t2);
  }
  void insert(T v) {
    auto s = split(node, v);
    auto n = new Node(v);
    node = merge(s.first, n);
    node = merge(node, s.second);
  }
  void erase(int v) {
    auto s1 = split(node, v - 1);
    auto s2 = split(s1.second, v);
    merge(s1.first, s2.second);
  }
  int getcount(Node* t, T v, bool larger) {
    if (!t) return 0;
    int ret = 0;
    if (larger) {
      if (v <= t->val) ret++;
      ret += v <= t->val ? count(t->rch) : getcount(t->rch, v, larger);
      ret += v <= t->val ? getcount(t->lch, v, larger) : 0;
    } else {
      if (v >= t->val) ret++;
      ret += v >= t->val ? count(t->lch) : getcount(t->lch, v, larger);
      ret += v >= t->val ? getcount(t->rch, v, larger) : 0;
    }
    return ret;
  }
  int getcount(T v, bool larger) { return getcount(node, v, larger); }
  T getsum(Node* t, T v, bool larger) {
    if (!t) return 0;
    T ret = 0;
    if (larger) {
      if (v <= t->val) ret += t->val;
      ret += v <= t->val ? sum(t->rch) : getsum(t->rch, v, larger);
      ret += v <= t->val ? getsum(t->lch, v, larger) : 0;
    } else {
      if (v >= t->val) ret += t->val;
      ret += v >= t->val ? sum(t->lch) : getsum(t->lch, v, larger);
      ret += v >= t->val ? getsum(t->rch, v, larger) : 0;
    }
    return ret;
  }
  T getsum(T v, bool larger) { return getsum(node, v, larger); }
};
int main() {
  int64_t i, j, k;
  int N, K;
  cin >> N >> K;
  vector<vector<int>> RXQ(N);
  for (i = 0; i < N; i++) {
    int x, r, q;
    scanf("%d %d %d", &x, &r, &q);
    RXQ[i] = {r, x, q};
  }
  sort(RXQ.rbegin(), RXQ.rend());
  map<int, Treap<int>> trees;
  int64_t ans = 0;
  for (auto&& v : RXQ) {
    int r = v[0], x = v[1], q = v[2];
    for (k = q - K; k <= q + K; k++) {
      if (trees.count(k)) {
        ans +=
            trees[k].getcount(x - r, true) - trees[k].getcount(x + r + 1, true);
      }
    }
    trees.count(q) ? trees[q].insert(x) : trees[q].initialize(x);
  }
  cout << ans << endl;
  return 0;
}