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;
mt19937 randGenerator(27081999);
struct Treap {
  long long key;
  int priority, subtreeSize;
  Treap *left, *right;
  Treap(long long pKey = 0) {
    key = pKey;
    subtreeSize = 1;
    priority = randGenerator();
    left = nullptr;
    right = nullptr;
  }
  void recalc() {
    subtreeSize = 1;
    subtreeSize += (left == nullptr ? 0 : left->subtreeSize);
    subtreeSize += (right == nullptr ? 0 : right->subtreeSize);
  }
  long long find_kth(int k) {
    if (key == k) {
      return 1ll + (right == nullptr ? 0ll : right->subtreeSize);
    } else if (key < k) {
      return (right == nullptr ? 0ll : right->find_kth(k));
    } else {
      return 1ll + (right == nullptr ? 0ll : right->subtreeSize) +
             (left == nullptr ? 0ll : left->find_kth(k));
    }
  }
};
Treap *root[100000] = {nullptr};
Treap *merge(Treap *sm, Treap *bg) {
  if (sm == nullptr) {
    return bg;
  } else if (bg == nullptr) {
    return sm;
  }
  if (sm->priority > bg->priority) {
    sm->right = merge(sm->right, bg);
    sm->recalc();
    return sm;
  } else {
    bg->left = merge(sm, bg->left);
    bg->recalc();
    return bg;
  }
}
pair<Treap *, Treap *> split(Treap *t, long long key) {
  if (t == nullptr) {
    return {nullptr, nullptr};
  }
  if (t->key < key) {
    auto splitResults = split(t->right, key);
    t->right = splitResults.first;
    t->recalc();
    return {t, splitResults.second};
  } else {
    auto splitResults = split(t->left, key);
    t->left = splitResults.second;
    t->recalc();
    return {splitResults.first, t};
  }
}
void add_number(long long x, int i) {
  if (root[i] == nullptr) {
    root[i] = new Treap(x);
    return;
  }
  Treap *newTreap = new Treap(x);
  auto splitResults = split(root[i], x);
  splitResults.first = merge(splitResults.first, newTreap);
  root[i] = merge(splitResults.first, splitResults.second);
}
void remove_number(long long x, int i) {
  auto splitResults1 = split(root[i], x);
  auto splitResults2 = split(splitResults1.second, x + 1);
  root[i] = merge(splitResults1.first, splitResults2.second);
}
long long kth_number(int k, int i) {
  return (root[i] == nullptr ? 0ll : root[i]->find_kth(k));
}
int n, m, k;
struct robot {
  int x, r, q;
  bool operator<(robot rob) const { return x < rob.x; }
};
robot a[100001];
int lx[100001], rx[100001];
int lq[100001], rq[100001];
int iq[100001];
vector<int> IQ;
vector<int> sight[100001];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i].x >> a[i].r >> a[i].q;
    iq[i] = a[i].q;
  }
  sort(a, a + n);
  robot rob;
  for (int i = 0; i < n; i++) {
    rob.x = a[i].x - a[i].r - 1;
    lx[i] = upper_bound(a, a + n, rob) - a;
    rob.x = a[i].x + a[i].r;
    rx[i] = upper_bound(a, a + n, rob) - a - 1;
    sight[rx[i]].push_back(i);
  }
  sort(iq, iq + n);
  IQ.push_back(iq[0]);
  for (int i = 1; i < n; i++) {
    if (iq[i] != iq[i - 1]) IQ.push_back(iq[i]);
  }
  m = IQ.size();
  for (int i = 0; i < m; i++) {
    lq[i] = upper_bound(IQ.begin(), IQ.end(), IQ[i] - k - 1) - IQ.begin();
    rq[i] = upper_bound(IQ.begin(), IQ.end(), IQ[i] + k) - IQ.begin() - 1;
  }
  long long ans = 0ll;
  for (int i = 0; i < n; i++) {
    a[i].q = lower_bound(IQ.begin(), IQ.end(), a[i].q) - IQ.begin();
    for (int j = lq[a[i].q]; j <= rq[a[i].q]; j++) ans += kth_number(lx[i], j);
    add_number(i, a[i].q);
    for (int j : sight[i]) {
      remove_number(j, a[j].q);
    }
  }
  cout << ans << '\n';
  return 0;
}