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 = 1e5 + 7;
struct node {
  int key, prio, sz;
  int ch[2];
} treap[maxn];
int tot, root;
void rotate(int &rt, bool d) {
  int x = rt;
  rt = treap[rt].ch[!d];
  treap[x].ch[!d] = treap[rt].ch[d];
  treap[rt].ch[d] = x;
  treap[x].sz = treap[treap[x].ch[0]].sz + 1 + treap[treap[x].ch[1]].sz;
  treap[rt].sz = treap[treap[rt].ch[0]].sz + 1 + treap[treap[rt].ch[1]].sz;
}
int randint() {
  static int seed = 703;
  return seed = int(seed * 48271LL % 2147483647);
}
void ins(int &rt, int key) {
  if (!rt) {
    rt = ++tot;
    treap[rt].key = key;
    treap[rt].prio = randint();
    treap[rt].sz = 1;
  } else {
    int d;
    ins(treap[rt].ch[d = key > treap[rt].key], key);
    treap[rt].sz++;
    if (treap[rt].prio < treap[treap[rt].ch[d]].prio) rotate(rt, !d);
  }
}
bool erase(int &rt, int key) {
  if (!rt) return false;
  if (key != treap[rt].key) {
    if (erase(treap[rt].ch[key > treap[rt].key], key)) {
      treap[rt].sz--;
      return true;
    }
    return false;
  } else if (treap[rt].ch[0] == 0)
    rt = treap[rt].ch[1];
  else if (treap[rt].ch[1] == 0)
    rt = treap[rt].ch[0];
  else {
    int &lft = treap[rt].ch[0], &rgt = treap[rt].ch[1];
    bool d = treap[lft].prio > treap[rgt].prio;
    rotate(rt, d);
    erase(treap[rt].ch[d], key);
    treap[rt].sz--;
  }
  return true;
}
void getrank(int rt, int key, int &ans) {
  if (!rt) return;
  int nums = 0;
  if (key > treap[rt].key) {
    ans += treap[treap[rt].ch[0]].sz + 1;
    getrank(treap[rt].ch[1], key, ans);
  } else if (key == treap[rt].key) {
    ans += treap[treap[rt].ch[0]].sz + 1;
  } else {
    getrank(treap[rt].ch[0], key, ans);
  }
}
int X[maxn], R[maxn], Q[maxn];
int n, k;
priority_queue<pair<int, int> > PQ;
int idx = 0;
unordered_map<int, int> mp;
int roots[maxn];
int ss[maxn];
bool comp(int a, int b) { return X[a] < X[b]; }
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> X[i] >> R[i] >> Q[i];
    if (!mp[Q[i]]) {
      mp[Q[i]] = ++idx;
    }
  }
  for (int i = 1; i <= n; ++i) {
    ss[i] = i;
  }
  sort(ss + 1, ss + 1 + n, comp);
  long long ans = 0;
  PQ.push(make_pair(X[ss[n]] - R[ss[n]], ss[n]));
  ins(roots[mp[Q[ss[n]]]], X[ss[n]]);
  for (int i = n - 1; i >= 1; --i) {
    while (!PQ.empty() && PQ.top().first > X[ss[i]]) {
      int id = PQ.top().second;
      erase(roots[mp[Q[id]]], X[id]);
      PQ.pop();
    }
    for (int j = -k; j <= k; ++j) {
      int newIQ = j + Q[ss[i]];
      if (!mp[newIQ]) continue;
      int rk = 0;
      getrank(roots[mp[newIQ]], X[ss[i]] + R[ss[i]], rk);
      ans += rk;
    }
    ins(roots[mp[Q[ss[i]]]], X[ss[i]]);
    PQ.push(make_pair(X[ss[i]] - R[ss[i]], ss[i]));
  }
  cout << ans << endl;
}