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 N = 5e5 + 11;
const int MOD = 1e9 + 7;
map<int, int> mt;
vector<int> v[N];
int kol;
pair<int, pair<int, int> > a[N];
int x[N], y[N], d[N], num[N], tt[N], last[N];
int w[N * 4];
void update(int i, int l, int r, int x, int t) {
  if (l == r) {
    w[i] = t;
    return;
  }
  int mid = (l + r) / 2;
  if (x <= mid)
    update(i * 2, l, mid, x, t);
  else
    update(i * 2 + 1, mid + 1, r, x, t);
  w[i] = w[i * 2] + w[i * 2 + 1];
}
int get(int i, int l, int r, int tl, int tr) {
  if (tl <= l && r <= tr) return w[i];
  if (tl > r || l > tr) return 0;
  int mid = (l + r) / 2;
  return get(i * 2, l, mid, tl, tr) + get(i * 2 + 1, mid + 1, r, tl, tr);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first >> a[i].second.first >> a[i].second.second;
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    x[i] = a[i].first;
    y[i] = a[i].second.first;
    d[i] = a[i].second.second;
    if (mt[d[i]] == 0) {
      kol++;
      mt[d[i]] = kol;
    }
    v[mt[d[i]]].push_back(i);
  }
  int c = 0;
  for (int i = 1; i <= kol; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      c++;
      tt[c] = v[i][j];
      num[v[i][j]] = c;
    }
    last[i] = c;
  }
  set<pair<int, int> > st;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    while (st.size() > 0) {
      pair<int, int> p = *st.begin();
      if (p.first < x[i]) {
        st.erase(p);
        update(1, 1, n, num[p.second], 0);
      } else
        break;
    }
    for (int s = d[i] - m; s <= d[i] + m; s++)
      if (mt[s] != 0) {
        int j = mt[s];
        int l = 0, r = v[j].size() - 1;
        while (r - l > 1) {
          int mid = (l + r) / 2;
          if (x[v[j][mid]] < x[i] - y[i])
            l = mid;
          else
            r = mid;
        }
        if (x[v[j][l]] >= x[i] - y[i])
          ans += 1ll * get(1, 1, n, num[v[j][l]], last[j]);
        else if (x[v[j][r]] >= x[i] - y[i])
          ans += 1ll * get(1, 1, n, num[v[j][r]], last[j]);
      }
    st.insert(make_pair(x[i] + y[i], i));
    update(1, 1, n, num[i], 1);
  }
  cout << ans << endl;
}