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;
#pragma gcc diagnostic warning "-std=c++11"
const int N = 100010;
vector<int> f[N];
vector<vector<int>> t[N];
unordered_map<int, vector<int>> same;
int n, k, x[N], r[N], iq[N], id[N];
unordered_map<int, int> comp;
bool cmp(int i, int j) { return x[i] < x[j]; }
int query(int cur_iq, int l, int r, int x) {
  int ret = 0, sz = f[cur_iq].size();
  for (l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
    if (l & 1)
      ret += (upper_bound(t[cur_iq][l].begin(), t[cur_iq][l].end(), x) -
              t[cur_iq][l].begin()),
          ++l;
    if (r & 1)
      --r, ret += (upper_bound(t[cur_iq][r].begin(), t[cur_iq][r].end(), x) -
                   t[cur_iq][r].begin());
  }
  return ret;
}
inline int get(int cur_iq, int l, int r) {
  if (comp.find(cur_iq) == comp.end()) return 0;
  int it = comp[cur_iq];
  return query(it, upper_bound(f[it].begin(), f[it].end(), r) - f[it].begin(),
               upper_bound(f[it].begin(), f[it].end(), l) - f[it].begin(), r);
}
void brute() {
  int yo = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      int ii = i, jj = j;
      if (x[ii] > x[jj]) swap(ii, jj);
      if (x[jj] <= x[ii] + r[ii] and x[jj] - r[jj] <= x[ii] and
          abs(iq[ii] - iq[jj]) <= k) {
        ++yo;
      }
    }
  }
  cout << yo << '\n';
}
vector<int> tmp;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d %d", x + i, r + i, iq + i);
    same[x[i]].push_back(iq[i]);
    id[i] = i;
    tmp.push_back(iq[i]);
  }
  sort(tmp.begin(), tmp.end());
  tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
  for (int i = 0; i < tmp.size(); ++i) {
    comp[tmp[i]] = i;
  }
  sort(id + 1, id + n + 1, cmp);
  for (int it = 1; it <= n; ++it) {
    int i = id[it];
    f[comp[iq[i]]].push_back(i);
  }
  for (int it = 0; it < tmp.size(); ++it) {
    int cur_iq = tmp[it];
    int sz = f[it].size();
    vector<vector<int>> &tr = t[it];
    tr.resize(sz + sz);
    for (int j = 0; j < sz; ++j) {
      tr[sz + j].push_back(x[f[it][j]] - r[f[it][j]]);
      f[it][j] = x[f[it][j]];
    }
    for (int j = sz - 1; j; --j) {
      merge(tr[j << 1].begin(), tr[j << 1].end(), tr[j << 1 | 1].begin(),
            tr[j << 1 | 1].end(), back_inserter(tr[j]));
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int cur_iq = iq[i];
    for (int j = cur_iq - k; j <= cur_iq + k; ++j) {
      ans += (long long)get(j, x[i] + r[i], x[i]);
    }
  }
  for (auto it : same) {
    vector<int> &v = it.second;
    int sz = v.size();
    sort(v.begin(), v.end());
    for (int i = 0, j = 0; i < sz; ++i) {
      while (j + 1 < sz and v[j + 1] - v[i] <= k) {
        ++j;
      }
      ans += (j - i);
    }
  }
  printf("%lld\n", ans);
  return 0;
}