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;
struct splay_node {
  splay_node *parent, *child[2];
  int value;
  int size;
  splay_node() : parent(nullptr), child{nullptr, nullptr}, size(1) {}
  static int get_size(splay_node *x) { return x == nullptr ? 0 : x->size; }
  int parent_index() const { return this == parent->child[0] ? 0 : 1; }
  void set_child(int index, splay_node *x) {
    child[index] = x;
    if (x != nullptr) x->parent = this;
  }
  void join() { size = get_size(child[0]) + get_size(child[1]) + 1; }
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count() *
            ((uint64_t) new char | 1));
struct splay_tree {
  static const int POOL_SIZE = 10000;
  static vector<splay_node *> node_pool;
  static const int SPLAY_PROBABILITY = 10;
  splay_node *root;
  int tree_size;
  splay_tree() : root(nullptr), tree_size(0) {}
  static splay_node *new_node() {
    if (node_pool.empty()) {
      splay_node *ptr = new splay_node[POOL_SIZE];
      for (int i = 0; i < POOL_SIZE; i++) node_pool.push_back(ptr + i);
    }
    splay_node *node = node_pool.back();
    node_pool.pop_back();
    return node;
  }
  void rotate_up(splay_node *x) {
    splay_node *p = x->parent, *gp = p->parent;
    int index = x->parent_index();
    if (gp == nullptr) {
      x->parent = nullptr;
      root = x;
    } else {
      gp->set_child(p->parent_index(), x);
    }
    p->set_child(index, x->child[!index]);
    x->set_child(!index, p);
    p->join();
  }
  void splay(splay_node *x) {
    while (x != root) {
      splay_node *p = x->parent;
      if (p != root) rotate_up(x->parent_index() == p->parent_index() ? p : x);
      rotate_up(x);
    }
    x->join();
  }
  void randomized_splay(splay_node *x) {
    if (rng() % 100 < SPLAY_PROBABILITY) splay(x);
  }
  splay_node *insert(const int &value) {
    splay_node *x = new_node();
    x->value = value;
    tree_size++;
    if (root == nullptr) return root = x;
    splay_node *current = root, *prev = nullptr;
    while (current != nullptr) {
      prev = current;
      current->size++;
      current = current->child[value < current->value ? 0 : 1];
    }
    prev->set_child(value < prev->value ? 0 : 1, x);
    randomized_splay(x);
    return x;
  }
  splay_node *root_successor() {
    splay_node *x = root->child[1];
    while (x->child[0] != nullptr) x = x->child[0];
    return x;
  }
  void erase(splay_node *x) {
    splay(x);
    if (x->child[0] == nullptr) {
      root = x->child[1];
    } else if (x->child[1] == nullptr) {
      root = x->child[0];
    } else {
      splay(root_successor());
      assert(root->child[0] == x && x->child[1] == nullptr);
      root->set_child(0, x->child[0]);
      root->size--;
    }
    if (root != nullptr) root->parent = nullptr;
    *x = splay_node();
    node_pool.push_back(x);
    tree_size--;
  }
  pair<splay_node *, int> lower_bound(const int &value) {
    splay_node *current = root, *prev = nullptr, *answer = nullptr;
    int below = 0;
    while (current != nullptr) {
      prev = current;
      if (current->value < value) {
        below += splay_node::get_size(current->child[0]) + 1;
        current = current->child[1];
      } else {
        answer = current;
        current = current->child[0];
      }
    }
    if (prev != nullptr) randomized_splay(prev);
    return make_pair(answer, below);
  }
  bool erase(const int &value) {
    splay_node *x = lower_bound(value).first;
    if (x == nullptr || x->value != value) return false;
    erase(x);
    return true;
  }
  int less_than(const int &value) { return lower_bound(value).second; }
  int less_equal(const int &value) {
    assert(is_integral<int>::value);
    return less_than(value + 1);
  }
  splay_node *node_at_index(int index) {
    if (index < 0 || index >= tree_size) return nullptr;
    splay_node *current = root;
    while (current != nullptr) {
      int left_size = splay_node::get_size(current->child[0]);
      if (index == left_size) {
        randomized_splay(current);
        return current;
      }
      if (index < left_size) {
        current = current->child[0];
      } else {
        current = current->child[1];
        index -= left_size + 1;
      }
    }
    assert(false);
  }
};
vector<splay_node *> splay_tree::node_pool;
struct robot {
  int x, radius, iq;
  bool operator<(const robot &other) const { return radius > other.radius; }
};
int N, K;
vector<robot> robots;
map<int, splay_tree> iq_map;
int main() {
  scanf("%d %d", &N, &K);
  robots.resize(N);
  for (robot &r : robots) scanf("%d %d %d", &r.x, &r.radius, &r.iq);
  sort(robots.begin(), robots.end());
  long long total = 0;
  for (robot &r : robots) {
    for (int iq = r.iq - K; iq <= r.iq + K; iq++)
      if (iq_map.count(iq))
        total += iq_map[iq].less_equal(r.x + r.radius) -
                 iq_map[iq].less_than(r.x - r.radius);
    iq_map[r.iq].insert(r.x);
  }
  printf("%lld\n", total);
}