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;
vector<int> f1, f2;
void add(vector<int>& f, int ind) {
  for (int i = ind; i < f.size(); i |= i + 1) {
    f[i]++;
  }
}
int sum(vector<int>& f, int ind) {
  int ans = 0;
  for (int i = ind; i >= 0; i = (i & (i + 1)) - 1) {
    ans += f[i];
  }
  return ans;
}
int sum(vector<int>& f, int l, int r) {
  if (l == 0) return sum(f, r);
  return sum(f, r) - sum(f, l - 1);
}
long long solve(const vector<pair<pair<int, int>, int>>& by_x,
                const vector<pair<pair<int, int>, int>>& by_r, int iq) {
  long long ans = 0;
  f1.assign(by_x.size() + 1, 0);
  f2.assign(by_x.size() + 1, 0);
  for (int i = 0; i < by_r.size(); i++) {
    int r = by_r[i].first.first;
    int x = by_r[i].first.second;
    int q = by_r[i].second;
    int ind_x = (int)distance(
        by_x.begin(),
        lower_bound(by_x.begin(), by_x.end(), make_pair(make_pair(x, r), q)));
    int ind_l = (int)distance(by_x.begin(),
                              lower_bound(by_x.begin(), by_x.end(),
                                          make_pair(make_pair(x - r, -1), -1)));
    int ind_r =
        (int)distance(by_x.begin(),
                      lower_bound(by_x.begin(), by_x.end(),
                                  make_pair(make_pair(x + r + 1, -1), -1))) -
        1;
    if (q == iq) {
      ans += sum(f1, ind_l, ind_r);
      add(f2, ind_x);
    }
    add(f1, ind_x);
    if (q != iq) {
      ans += sum(f2, ind_l, ind_r);
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<pair<int, pair<int, int>>> sorted_q;
  for (int i = 0; i < n; i++) {
    int x, r, q;
    cin >> x >> r >> q;
    sorted_q.push_back({q, {x, r}});
  }
  sort(sorted_q.begin(), sorted_q.end());
  long long ans = 0;
  for (int i = 0; i < sorted_q.size();) {
    vector<pair<pair<int, int>, int>> by_x, by_r;
    int j = i;
    while (j < sorted_q.size() && sorted_q[i].first + k >= sorted_q[j].first) {
      int x = sorted_q[j].second.first;
      int r = sorted_q[j].second.second;
      int q = sorted_q[j].first;
      by_x.push_back({{x, r}, q});
      by_r.push_back({{r, x}, q});
      j++;
    }
    sort(by_x.begin(), by_x.end());
    sort(by_r.rbegin(), by_r.rend());
    ans += solve(by_x, by_r, sorted_q[i].first);
    int ne_i = i;
    while (ne_i < sorted_q.size() &&
           sorted_q[i].first == sorted_q[ne_i].first) {
      ne_i++;
    }
    i = ne_i;
  }
  cout << ans << endl;
  return 0;
}