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 int MAXN = 100005;
struct Node *nil = 0;
struct Node {
  int val, sz, h;
  Node *lc, *rc;
  Node() {}
  Node(int x) : val(x), sz(1), h(rand()), lc(nil), rc(nil) {}
  inline void update() { sz = (lc ? lc->sz : 0) + (rc ? rc->sz : 0) + 1; }
} node[MAXN * 20];
int pnode = 0;
inline Node *newnode(int x) {
  node[pnode] = Node(x);
  return &node[pnode++];
}
Node *merge(Node *a, Node *b) {
  if (!a) return b;
  if (!b) return a;
  if (a->h < b->h) {
    a->rc = merge(a->rc, b), a->update();
    return a;
  } else {
    b->lc = merge(a, b->lc), b->update();
    return b;
  }
}
pair<Node *, Node *> split(Node *p, int k) {
  if (!p) return make_pair(nil, nil);
  if (k >= p->val) {
    pair<Node *, Node *> y = split(p->rc, k);
    p->rc = y.first, p->update();
    return make_pair(p, y.second);
  } else {
    pair<Node *, Node *> y = split(p->lc, k);
    p->lc = y.second, p->update();
    return make_pair(y.first, p);
  }
}
void insert(Node *&root, int k) {
  pair<Node *, Node *> y = split(root, k);
  root = merge(y.first, merge(newnode(k), y.second));
}
void erase(Node *&root, int k) {
  pair<Node *, Node *> y = split(root, k);
  pair<Node *, Node *> x = split(y.first, k - 1);
  if (x.second) x.second = merge(x.second->lc, x.second->rc);
  root = merge(merge(x.first, x.second), y.second);
}
int query(Node *&root, int l, int r) {
  pair<Node *, Node *> y = split(root, r);
  pair<Node *, Node *> x = split(y.first, l - 1);
  int ret = (x.second ? x.second->sz : 0);
  root = merge(merge(x.first, x.second), y.second);
  return ret;
}
int N = 0;
Node *root[MAXN << 1];
inline int lowbit(int x) { return x & -x; }
void insert(int pos, int val) {
  for (int i = pos; i <= N; i += lowbit(i)) insert(root[i], val);
}
void erase(int pos, int val) {
  for (int i = pos; i <= N; i += lowbit(i)) erase(root[i], val);
}
int query(int pos, int l, int r) {
  int ret = 0;
  for (int i = pos; i > 0; i ^= lowbit(i)) ret += query(root[i], l, r);
  return ret;
}
struct Opt {
  int tp, x, id, q;
  Opt() {}
  Opt(int a, int b, int c, int d) : tp(a), x(b), id(c), q(d) {}
};
bool operator<(const Opt &a, const Opt &b) {
  return (a.x == b.x ? a.tp < b.tp : a.x < b.x);
}
vector<Opt> opt;
int n, k, x[MAXN], r[MAXN], q[MAXN];
long long res = 0;
map<int, int> cnt;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &x[i], &r[i], &q[i]);
    opt.emplace_back(Opt(1, x[i], i, q[i]));
    opt.emplace_back(Opt(-1, x[i] + r[i] + 1, i, q[i]));
    cnt[x[i]] = 0, cnt[x[i] - r[i] - 1] = 0;
  }
  for (auto &x : cnt) x.second = ++N;
  sort(opt.begin(), opt.end());
  for (auto w : opt) {
    if (w.tp == -1)
      erase(cnt[x[w.id]], w.q);
    else {
      int val = query(cnt[x[w.id]], w.q - k, w.q + k) -
                query(cnt[x[w.id] - r[w.id] - 1], w.q - k, w.q + k);
      res += val;
      insert(cnt[x[w.id]], w.q);
    }
  }
  printf("%I64d\n", res);
  return 0;
}