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 nn = 1e5 + 8;
const int R = 1e9;
struct node {
  int value;
  node *left, *right;
  node() {
    value = 0;
    left = right = NULL;
  }
};
map<int, node *> iq;
tuple<int, int, int> a[nn];
int n, k;
void update(node *&t, int l, int r, int x, int v) {
  if (t == NULL) t = new node();
  if (l > x || r < x) return;
  if (l == x && r == x) {
    t->value += v;
    return;
  }
  int m = (l + r) >> 1;
  update(t->left, l, m, x, v);
  update(t->right, m + 1, r, x, v);
  t->value = t->left->value + t->right->value;
}
int get(node *&t, int l, int r, int x, int y) {
  if (l > y || r < x || t == NULL) return 0;
  if (l >= x && r <= y) return t->value;
  int m = (l + r) >> 1;
  return get(t->left, l, m, x, y) + get(t->right, m + 1, r, x, y);
}
long long calc() {
  long long res = 0;
  map<pair<int, int>, int> p;
  for (int i = 1; i <= n; i++) {
    int x, r, q;
    tie(x, r, q) = a[i];
    while (!p.empty() && p.begin()->first.first < x) {
      pair<int, int> tmp = p.begin()->first;
      tuple<int, int, int> &j = a[tmp.second];
      update(iq[get<2>(j)], 0, R, get<0>(j), -1);
      p[tmp]--;
      if (p[tmp] == 0) {
        p.erase(tmp);
      }
    }
    for (int j = -k; j <= k; j++) {
      if (iq.find(q + j) != iq.end()) {
        res += get(iq[q + j], 0, R, max(0, x - r), x);
      }
    }
    update(iq[q], 0, R, x, 1);
    p[{x + r, i}]++;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x, r, q;
    cin >> x >> r >> q;
    a[i] = make_tuple(x, r, q);
  }
  sort(a + 1, a + 1 + n);
  cout << calc();
}