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;
struct robot {
  int x, r, s;
  inline bool operator<(const robot &a) const { return x < a.x; }
};
struct node {
  int x;
  node *l, *r;
  node() {
    x = 0;
    l = r = 0;
  }
  node(int xx) {
    x = xx;
    l = r = 0;
  }
};
inline void upd(node *t, int Tl, int Tr, int x, int delta) {
  if (Tl > x || Tr < x) {
    return;
  }
  if (Tl == x && Tr == x) {
    t->x += delta;
    return;
  }
  int mid = (Tl + Tr) / 2;
  if (x <= mid) {
    if (!t->l) t->l = new node();
    upd(t->l, Tl, mid, x, delta);
  } else {
    if (!t->r) t->r = new node();
    upd(t->r, mid + 1, Tr, x, delta);
  }
  t->x = 0;
  if (t->l) t->x += t->l->x;
  if (t->r) t->x += t->r->x;
}
inline int get(node *t, int Tl, int Tr, int l, int r) {
  if (Tl > r || Tr < l) return 0;
  if (!t) return 0;
  if (l <= Tl && Tr <= r) return t->x;
  int mid = (Tl + Tr) / 2;
  return get(t->l, Tl, mid, l, r) + get(t->r, mid + 1, Tr, l, r);
}
const int N = 1e5 + 100;
robot a[N];
unordered_map<int, node *> c;
inline void upd(int s, int x, int val) {
  if (c[s] == nullptr) c[s] = new node();
  x = max(x, 0);
  x = min(x, (int)1e9);
  upd(c[s], 0, 1e9, x, val);
}
inline int get(int s, int x) {
  x = max(x, 0);
  x = min(x, (int)1e9);
  return get(c[s], 0, 1e9, x, 1e9);
}
inline int get(int s, int x, int r) { return get(s, x - r); }
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int x, r, s;
    cin >> x >> r >> s;
    a[i] = {x, r, s};
  }
  sort(a, a + n);
  multiset<pair<int, pair<int, int> > > Set;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    while (Set.size() && Set.begin()->first < a[i].x) {
      auto val = Set.begin()->second;
      upd(val.first, val.second, -1);
      Set.erase(Set.begin());
    }
    for (int j = a[i].s - k; j <= a[i].s + k; ++j) {
      ans += get(j, a[i].x, a[i].r);
    }
    Set.insert(make_pair(a[i].x + a[i].r, make_pair(a[i].s, a[i].x)));
    upd(a[i].s, a[i].x, 1);
  }
  cout << ans;
  return 0;
}