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;
using ll = long long int;
using ull = unsigned long long int;
using dd = double;
using ldd = long double;
using si = short int;
using usi = unsigned short int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
struct me {
  pair<int, int> x;
  ll y;
  me *l, *r;
  int cnt;
  me() {
    cnt = 0;
    l = r = nullptr;
    y = ((ll)rand() << 17) + rand();
  }
};
using pme = me*;
int cnt(pme t) { return (t ? t->cnt : 0); }
void upd(pme t) {
  if (t) t->cnt = 1 + cnt(t->l) + cnt(t->r);
}
void mer(pme& t, pme l, pme r) {
  if (!l || !r) {
    t = (l ? l : r);
    return;
  }
  if (l->y > r->y) {
    t = l;
    mer(l->r, l->r, r);
  } else {
    t = r;
    mer(r->l, l, r->l);
  }
  upd(t);
}
void split(pme t, pair<int, int> key, pme& l, pme& r) {
  if (!t) {
    l = r = nullptr;
    return;
  }
  if (key < t->x) {
    r = t;
    split(t->l, key, l, r->l);
  } else {
    l = t;
    split(t->r, key, t->r, r);
  }
  upd(l);
  upd(r);
}
void er(pme& t, pair<int, int> key) {
  if (!t) return;
  if (t->x == key)
    mer(t, t->l, t->r);
  else if (t->x < key)
    er(t->r, key);
  else
    er(t->l, key);
  upd(t);
}
void ins(pme& t, pme key) {
  if (!t) {
    t = key;
  } else if (key->y > t->y) {
    split(t, key->x, key->l, key->r);
    t = key;
  } else
    ins(key->x < t->x ? t->l : t->r, key);
  upd(t);
}
struct my {
  pme tree = nullptr;
  void era(pair<int, int> a) {
    er(tree, a);
    return;
  }
  int cnt_upper(pair<int, int> a) {
    pme l, r;
    split(tree, a, l, r);
    int ans = cnt(r);
    mer(tree, l, r);
    return ans;
  }
  void append(pair<int, int> a) {
    pme n = new me;
    n->x = a;
    ins(tree, n);
    return;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<pair<pii, int>> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i].first.first;
    cin >> arr[i].first.second;
    cin >> arr[i].second;
  }
  sort((arr).begin(), (arr).end());
  ll ans = 0;
  map<int, my> in;
  set<pair<int, int>> era;
  for (int i = 0; i < n; ++i) {
    while (era.size() > 0 && (*era.begin()).first < arr[i].first.first) {
      0;
      int ind = (*era.begin()).second;
      era.erase(era.begin());
      in[arr[ind].second].era({arr[ind].first.first, ind});
    }
    era.insert({arr[i].first.first + arr[i].first.second, i});
    for (int jj = max(arr[i].second - k, 0); jj <= arr[i].second + k; ++jj) {
      auto j = in.find(jj);
      if (j != in.end()) {
        ans += (*j).second.cnt_upper(
            {arr[i].first.first - arr[i].first.second, -1});
      }
    }
    in[arr[i].second].append({arr[i].first.first, i});
    0;
  }
  cout << ans;
}