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 long long MAXN = 1e5 + 7;
long long n, k;
long long x[MAXN], r[MAXN], q[MAXN];
void read() {
  cin >> n >> k;
  for (long long i = 0; i < n; ++i) cin >> x[i] >> r[i] >> q[i];
}
namespace treap {
mt19937 rnd(228);
struct Node {
  long long x, y, cnt;
  Node *l, *r;
  Node(long long x_) {
    x = x_;
    y = rnd();
    cnt = 1;
    l = r = NULL;
  }
};
long long cnt(Node *t) {
  if (!t)
    return 0;
  else
    return t->cnt;
}
void relax(Node *t) { t->cnt = cnt(t->l) + cnt(t->r) + 1; }
Node *merge(Node *l, Node *r) {
  if (!l) return r;
  if (!r) return l;
  if (l->y < r->y) {
    l->r = merge(l->r, r);
    relax(l);
    return l;
  } else {
    r->l = merge(l, r->l);
    relax(r);
    return r;
  }
}
pair<Node *, Node *> split(Node *t, long long x) {
  if (!t) return {NULL, NULL};
  if (t->x <= x) {
    auto tmp = split(t->r, x);
    t->r = tmp.first;
    relax(t);
    return {t, tmp.second};
  } else {
    auto tmp = split(t->l, x);
    t->l = tmp.second;
    relax(t);
    return {tmp.first, t};
  }
}
Node *insert(Node *t, long long x) {
  auto tmp = split(t, x);
  return merge(merge(tmp.first, new Node(x)), tmp.second);
}
Node *erase(Node *t, long long x) {
  auto tmp1 = split(t, x - 1);
  auto tmp2 = split(tmp1.second, x);
  tmp2.first = merge(tmp2.first->l, tmp2.first->r);
  return merge(merge(tmp1.first, tmp2.first), tmp2.second);
}
};  // namespace treap
using namespace treap;
struct Comp {
  bool operator()(const long long i, const long long j) const {
    return (x[i] + r[i] < x[j] + r[j]) || (x[i] + r[i] == x[j] + r[j] && i < j);
  }
};
bool comp(long long i, long long j) { return x[i] < x[j]; }
map<long long, Node *> d;
map<long long, vector<long long> > close;
set<long long, Comp> ms;
void add(long long i) {
  if (d.find(q[i]) == d.end()) d[q[i]] = NULL;
  d[q[i]] = insert(d[q[i]], x[i]);
  ms.insert(i);
}
void del(long long i) {
  d[q[i]] = erase(d[q[i]], x[i]);
  ms.erase(i);
}
long long ans = 0;
long long per[MAXN];
void solve() {
  for (long long i = 0; i < n; ++i) per[i] = i;
  sort(per, per + n, comp);
  for (long long i = 0; i < n; ++i) {
    long long num = per[i];
    while (ms.size() && x[*ms.begin()] + r[*ms.begin()] < x[num]) {
      del(*ms.begin());
    }
    long long sum = 0;
    for (long long j = q[num] - k; j <= q[num] + k; ++j) {
      if (d.find(j) == d.end()) continue;
      auto tmp = split(d[j], x[num] - r[num] - 1);
      ans += cnt(tmp.second);
      sum += cnt(tmp.second);
      d[j] = merge(tmp.first, tmp.second);
    }
    add(num);
  }
}
void print() { cout << ans << '\n'; }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  read();
  solve();
  print();
  return 0;
}