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 MAXN = 1e5 + 1;
struct Node {
  int val, size;
  Node *ls, *rs;
  Node(int _val, int _size, Node *_ls, Node *_rs)
      : val(_val), size(_size), ls(_ls), rs(_rs) {}
  Node() {}
  inline void pushup() {
    if (!ls->size) return;
    val = rs->val, size = ls->size + rs->size;
  }
} pool[MAXN << 1], *st[MAXN << 1], *null;
int cnt;
inline Node *newNode(int val, int size, Node *ls, Node *rs) {
  return &(*st[cnt++] = Node(val, size, ls, rs));
}
struct LFT {
  Node *root;
  inline Node *merge(Node *ls, Node *rs) {
    return newNode(rs->val, ls->size + rs->size, ls, rs);
  }
  inline void maintain(Node *cur) {
    Node *&ls = cur->ls, *&rs = cur->rs;
    if (ls->size > rs->size * 4)
      rs = merge(ls->rs, rs), st[--cnt] = ls, ls = ls->ls;
    if (rs->size > ls->size * 4)
      ls = merge(ls, rs->ls), st[--cnt] = rs, rs = rs->rs;
  }
  void insert(int x, Node *cur) {
    if (cur->size == 1)
      cur->ls = newNode(min(cur->val, x), 1, null, null),
      cur->rs = newNode(max(cur->val, x), 1, null, null);
    else
      insert(x, x > cur->ls->val ? cur->rs : cur->ls);
    cur->pushup();
    maintain(cur);
  }
  void erase(int x, Node *cur, Node *fa) {
    if (cur->size == 1)
      *fa = fa->ls == cur ? *fa->rs : *fa->ls;
    else
      erase(x, x > cur->ls->val ? cur->rs : cur->ls, cur);
    cur->pushup();
    maintain(cur);
  }
  int kth(int x, Node *cur) {
    if (cur->size == 1) return cur->val;
    return x > cur->ls->size ? kth(x - cur->ls->size, cur->rs)
                             : kth(x, cur->ls);
  }
  int Rank(int x, Node *cur) {
    if (cur->size == 1) return x > cur->val;
    return x > cur->ls->val ? Rank(x, cur->rs) + cur->ls->size
                            : Rank(x, cur->ls);
  }
  LFT() { root = new Node(2147483647, 1, null, null); }
} num[100005];
int n, k;
struct node {
  int p, r;
  int q;
} T[100005];
vector<int> V;
map<int, int> mp;
bool cmp(node a, node b) { return a.r < b.r; }
int b[100005];
int main() {
  for (int i = 0; i < (MAXN << 1); ++i) st[i] = &pool[i];
  null = new Node(0, 0, 0, 0);
  scanf("%d%d", &n, &k);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int p, r, q;
    scanf("%d%d%d", &p, &r, &q);
    T[i].p = p, T[i].r = r;
    T[i].q = q;
    V.push_back(q);
  }
  sort(V.begin(), V.end());
  V.erase(unique(V.begin(), V.end()), V.end());
  for (int i = 0; i < V.size(); i++) {
    mp.insert(pair<int, int>{V[i], i + 1});
  }
  sort(T + 1, T + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    map<int, int>::iterator it = mp.find(T[i].q);
    b[it->second]++;
  }
  for (int i = 1; i <= n; i++) {
    map<int, int>::iterator it = mp.find(T[i].q);
    num[it->second].insert(T[i].p, num[it->second].root);
  }
  for (int i = 1; i <= n; i++) {
    map<int, int>::iterator it = mp.find(T[i].q);
    num[it->second].erase(T[i].p, num[it->second].root, null);
    int l = max(0, T[i].p - T[i].r), r = T[i].p + T[i].r;
    for (int j = max(0, T[i].q - k); j <= T[i].q + k; j++) {
      map<int, int>::iterator it = mp.find(j);
      if (it == mp.end()) continue;
      int a = num[it->second].Rank(r + 1, num[it->second].root);
      int b = num[it->second].Rank(l, num[it->second].root);
      ans += a - b;
    }
  }
  cout << ans << endl;
  return 0;
}