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 N = 100000 + 1;
const int K = 20 + 1;
struct SegTree {
  SegTree *ls, *rs;
  int l, r, sum;
} * qtree[N * K * 2];
int qsize, xsize;
SegTree *make_new(int l, int r) {
  SegTree *ret = new SegTree();
  ret->l = l;
  ret->r = r;
  return ret;
}
void insert(SegTree *&o, int p) {
  if (o->l != o->r) {
    int mid = (o->l + o->r) / 2;
    if (p <= mid) {
      if (o->ls == 0x0) {
        o->ls = make_new(o->l, mid);
      }
      insert(o->ls, p);
    } else {
      if (o->rs == 0x0) {
        o->rs = make_new(mid + 1, o->r);
      }
      insert(o->rs, p);
    }
  }
  o->sum++;
}
void erase(SegTree *&o, int p) {
  if (o->l != o->r) {
    int mid = (o->l + o->r) / 2;
    if (p <= mid) {
      assert(o->ls != 0x0);
      erase(o->ls, p);
    } else {
      assert(o->rs != 0x0);
      erase(o->rs, p);
    }
  }
  o->sum--;
}
int query(SegTree *o, int qr) {
  if (o->l == o->r) {
    return o->sum;
  }
  int mid = (o->l + o->r) / 2;
  int ret = 0;
  if (qr <= mid) {
    ret += o->ls ? query(o->ls, qr) : 0;
  } else {
    ret += o->ls ? o->ls->sum : 0;
    ret += o->rs ? query(o->rs, qr) : 0;
  }
  return ret;
}
int query(SegTree *o, int ql, int qr) {
  return query(o, qr) - query(o, ql - 1);
}
int n, k;
vector<int> qs, xs;
vector<tuple<int, int, int>> event;
int x[N], r[N], q[N];
int ID(vector<int> &vec, int x) {
  return lower_bound(vec.begin(), vec.end(), x) - vec.begin() + 1;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", &x[i], &r[i], &q[i]);
    xs.push_back(x[i]);
    xs.push_back(x[i] - r[i]);
    xs.push_back(x[i] + r[i]);
    qs.push_back(q[i]);
    for (int j = 1; j <= k; j++) {
      qs.push_back(q[i] + j);
      qs.push_back(q[i] - j);
    }
  }
  sort(qs.begin(), qs.end());
  sort(xs.begin(), xs.end());
  qs.resize(distance(qs.begin(), unique(qs.begin(), qs.end())));
  xs.resize(distance(xs.begin(), unique(xs.begin(), xs.end())));
  for (int i = 1; i <= n; i++) {
    event.push_back(tuple<int, int, int>(x[i] - r[i], -1, i));
    event.push_back(tuple<int, int, int>(x[i], 0, i));
    event.push_back(tuple<int, int, int>(x[i] + r[i], 1, i));
  }
  sort(event.begin(), event.end());
  qsize = qs.size();
  xsize = xs.size();
  for (int i = 1; i <= qsize; i++) {
    qtree[i] = make_new(1, xsize);
  }
  long long ans = 0;
  for (auto tp : event) {
    int ev = get<1>(tp);
    int id = get<2>(tp);
    int q_val = ID(qs, q[id]);
    int x_val = ID(xs, x[id]);
    if (ev == -1) {
      insert(qtree[q_val], x_val);
    }
    if (ev == 1) {
      erase(qtree[q_val], x_val);
    }
    if (ev == 0) {
      int lx_val = ID(xs, x[id] - r[id]);
      int rx_val = ID(xs, x[id] + r[id]);
      for (int i = -k; i <= k; i++) {
        int q_val = ID(qs, q[id] + i);
        ans += query(qtree[q_val], lx_val, rx_val);
      }
    }
  }
  printf("%lld\n", (ans - n) / 2);
  return 0;
}