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 = 2e5 + 5;
int x[maxn];
int r[maxn];
int q[maxn];
int n, k;
int cid = 0;
int lpos[maxn], rpos[maxn];
int* tree[maxn];
vector<int> pos[maxn];
set<int> ayy;
map<int, int> lmao;
int lwb[maxn];
int pps[maxn];
int tot[maxn];
void add(int* t, int len, int pos, int d) {
  while (pos <= len) {
    t[pos] += d;
    pos += pos & -pos;
  }
}
int get(int* t, int r) {
  if (r == 0) return 0;
  int ans = 0;
  while (r) {
    ans += t[r];
    r -= r & -r;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  vector<pair<int, pair<int, int> > > kek;
  for (auto i = 0; i < n; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    kek.push_back(make_pair(a, make_pair(b, c)));
  }
  sort((kek).begin(), (kek).end());
  for (auto i = 0; i < n; ++i) {
    x[i] = kek[i].first;
    r[i] = kek[i].second.first;
    q[i] = kek[i].second.second;
    ayy.insert(q[i]);
  }
  for (auto c : ayy) {
    lmao[c] = cid++;
  }
  for (auto c : ayy) {
    int l = c - k, r = c + k;
    auto lt = ayy.lower_bound(l);
    auto rt = ayy.upper_bound(r);
    int i = lmao[c];
    if (rt == ayy.begin()) {
      rpos[i] = -1;
      continue;
    }
    --rt;
    int lp = *lt, rp = *rt;
    if (lp > rp) {
      rpos[i] = -1;
      continue;
    }
    lpos[i] = lmao[lp];
    rpos[i] = lmao[rp];
  }
  for (auto i = 0; i < n; ++i) {
    int p = lmao[q[i]];
    pps[i] = p;
    if (!pos[p].empty() && pos[p].back() == x[i]) continue;
    pos[p].push_back(x[i]);
  }
  for (auto i = 0; i < cid; ++i) {
    int sz = pos[i].size();
    tree[i] = new int[sz + 1];
    fill(tree[i], tree[i] + 1 + sz, 0);
  }
  set<pair<int, int> > s;
  long long ans = 0;
  for (auto i = 0; i < n; ++i) {
    while (!s.empty() && s.begin()->first < x[i]) {
      int p = pps[s.begin()->second];
      --tot[p];
      add(tree[p], pos[p].size(), lwb[s.begin()->second] + 1, -1);
      s.erase(s.begin());
    }
    int p = pps[i];
    for (auto j = lpos[p]; j < rpos[p] + 1; ++j) {
      int huy = lower_bound((pos[j]).begin(), (pos[j]).end(), x[i] - r[i]) -
                pos[j].begin();
      ans += tot[j] - get(tree[j], huy);
    }
    int j =
        lower_bound((pos[p]).begin(), (pos[p]).end(), x[i]) - pos[p].begin();
    lwb[i] = j;
    add(tree[p], pos[p].size(), j + 1, 1);
    ++tot[p];
    s.insert(make_pair(x[i] + r[i], i));
  }
  cout << ans;
}