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>
#pragma GCC optimize("O3")
using namespace std;
const int N = 600000;
int n, k;
int x[N], r[N], q[N];
vector<pair<int, int> > by_r;
vector<pair<pair<int, int>, int> > by_qx;
int where_in_second[N];
int t[N];
void add(int i, int delta) {
  for (; i < N; i = (i | (i + 1))) t[i] += delta;
}
int sum(int r) {
  int result = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) result += t[r];
  return result;
}
int solver(int iq, int L, int R) {
  L = lower_bound(by_qx.begin(), by_qx.end(), make_pair(make_pair(iq, L), -1)) -
      by_qx.begin();
  R = lower_bound(by_qx.begin(), by_qx.end(),
                  make_pair(make_pair(iq, R + 1), -1)) -
      by_qx.begin();
  --R;
  if (R < L) return 0;
  return sum(R) - sum(L - 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  cin >> k;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> r[i] >> q[i];
    by_r.push_back(make_pair(r[i], i));
    by_qx.push_back(make_pair(make_pair(q[i], x[i]), i));
  }
  sort(by_r.begin(), by_r.end());
  reverse(by_r.begin(), by_r.end());
  sort(by_qx.begin(), by_qx.end());
  for (int i = 0; i < by_qx.size(); i++) {
    int id = by_qx[i].second;
    where_in_second[id] = i;
  }
  long long ans = 0;
  for (int i = 0; i < by_r.size(); i++) {
    int id = by_r[i].second;
    int L = x[id] - r[id];
    int R = x[id] + r[id];
    int my_iq = q[id];
    for (int iq = my_iq - k; iq <= my_iq + k; iq++) {
      ans += solver(iq, L, R);
    }
    add(where_in_second[id], 1);
  }
  cout << ans << endl;
  return 0;
}