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 kNmax = 3e5 + 10;
int n, k, x[kNmax], r[kNmax], q[kNmax];
long long res;
vector<int> coords;
vector<int> robots;
map<int, int> normCoords;
map<int, int> aint[4 * kNmax];
void update(int node, int left, int right, int pos, int iq) {
  aint[node][iq]++;
  if (left == right) {
    return;
  }
  int mid = (left + right) / 2;
  if (pos <= mid) {
    update(2 * node, left, mid, pos, iq);
  } else {
    update(2 * node + 1, mid + 1, right, pos, iq);
  }
}
int query(int node, int left, int right, int leftbound, int rightbound,
          int iq) {
  if (leftbound <= left && right <= rightbound) {
    int res = 0;
    auto iter = aint[node].lower_bound(iq - k);
    while (iter != aint[node].end() && iter->first <= iq + k) {
      res += iter->second;
      ++iter;
    }
    return res;
  }
  int mid = (left + right) / 2;
  int res = 0;
  if (leftbound <= mid) {
    res += query(2 * node, left, mid, leftbound, rightbound, iq);
  }
  if (mid < rightbound) {
    res += query(2 * node + 1, mid + 1, right, leftbound, rightbound, iq);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    robots.push_back(i);
    cin >> x[i] >> r[i] >> q[i];
    coords.push_back(x[i]);
    coords.push_back(x[i] - r[i]);
    coords.push_back(x[i] + r[i]);
  }
  sort(coords.begin(), coords.end());
  coords.erase(unique(coords.begin(), coords.end()), coords.end());
  for (int i = 0; i < int(coords.size()); i++) {
    normCoords[coords[i]] = i + 1;
  }
  int mxSize = coords.size();
  sort(robots.begin(), robots.end(),
       [](int i1, int i2) { return r[i1] > r[i2]; });
  for (int i = 0; i < int(robots.size()); i++) {
    int idx = robots[i];
    res += query(1, 1, mxSize, normCoords[x[idx] - r[idx]],
                 normCoords[x[idx] + r[idx]], q[idx]);
    update(1, 1, mxSize, normCoords[x[idx]], q[idx]);
  }
  cout << res;
}