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 = 1000;
int off;
struct event {
  int pos;
  int kind;
  int idx;
  event(int a, int b, int c) {
    pos = a;
    kind = b;
    idx = c;
  }
};
struct robot {
  int x, r, q;
  int prev, next;
};
struct node {
  int l, r, s;
};
struct tree {
  vector<node> t;
  int rec_cnt;
  tree() { t.push_back(node()); }
  bool update_left(int w) {
    if (t[w].l) return false;
    t[w].l = t.size();
    t.push_back(node());
    return true;
  }
  bool update_right(int w) {
    if (t[w].r) return false;
    t[w].r = t.size();
    t.push_back(node());
    return true;
  }
  void add(int x) {
    rec_cnt = 0;
    add(0, off, 0, x);
  }
  void add(int p, int k, int w, int x) {
    rec_cnt++;
    if (rec_cnt > 30) {
      int x = 1 / 0;
    }
    t[w].s++;
    if (p + 1 == k) return;
    int m = (p + k) >> 1;
    if (x < m) {
      update_left(w);
      add(p, m, t[w].l, x);
    } else {
      update_right(w);
      add(m, k, t[w].r, x);
    }
  }
  void remove(int x) {
    rec_cnt = 0;
    remove(0, off, 0, x);
  }
  void remove(int p, int k, int w, int x) {
    rec_cnt++;
    if (rec_cnt > 30) {
      int x = 1 / 0;
    }
    t[w].s--;
    if (p + 1 == k) return;
    int m = (p + k) >> 1;
    if (x < m)
      remove(p, m, t[w].l, x);
    else
      remove(m, k, t[w].r, x);
  }
  int query(int l, int r) {
    rec_cnt = 0;
    return query(0, off, l, r + 1, 0);
  }
  int query(int beg, int end, int p, int k, int w) {
    rec_cnt++;
    if (rec_cnt > 30) {
      int x = 1 / 0;
    }
    if (p == beg && k == end) return t[w].s;
    int m = (beg + end) >> 1;
    if (k <= m) {
      if (t[w].l)
        return query(beg, m, p, k, t[w].l);
      else
        return 0;
    }
    if (p >= m) {
      if (t[w].r)
        return query(m, end, p, k, t[w].r);
      else
        return 0;
    }
    int l = (t[w].l ? query(beg, m, p, m, t[w].l) : 0);
    int r = (t[w].r ? query(m, end, m, k, t[w].r) : 0);
    return l + r;
  }
};
map<int, tree> T;
void renumerate(const vector<int> &v, int &x) {
  int beg = 0, mid, end = v.size();
  while (beg + 1 < end) {
    mid = (beg + end) >> 1;
    if (v[mid] <= x) {
      beg = mid;
    } else {
      end = mid;
    }
  }
  x = beg;
}
void solve() {
  long long res = 0;
  vector<event> ev;
  int n, K;
  cin >> n >> K;
  vector<int> renum;
  renum.push_back(0);
  vector<robot> rob(n);
  for (int i = 0; i < (n); ++i) {
    cin >> rob[i].x >> rob[i].r >> rob[i].q;
    rob[i].prev = max(rob[i].x - rob[i].r, 0);
    rob[i].next = rob[i].x + rob[i].r + 1;
    renum.push_back(rob[i].x);
    renum.push_back(rob[i].prev);
    renum.push_back(rob[i].next);
  }
  sort(renum.begin(), renum.end());
  auto it = unique(renum.begin(), renum.end());
  int nn = distance(renum.begin(), it);
  renum.resize(nn);
  off = 1;
  while (off < nn) off <<= 1;
  for (int i = 0; i < (n); ++i) {
    renumerate(renum, rob[i].x);
    renumerate(renum, rob[i].prev);
    renumerate(renum, rob[i].next);
    ev.push_back(event(rob[i].x, 1, i));
    ev.push_back(event(rob[i].next, 0, i));
  }
  sort(ev.begin(), ev.end(), [](const event &e0, const event &e1) {
    if (e0.pos != e1.pos) return e0.pos < e1.pos;
    return e0.kind == 0;
  });
  for (event e : ev) {
    robot &r = rob[e.idx];
    if (e.kind == 0) {
      T[r.q].remove(r.x);
    } else {
      for (int i = max(0, r.q - K); i <= r.q + K; ++i) {
        if (T.find(i) != T.end()) res += T[i].query(r.prev, r.x);
      }
      T[r.q].add(r.x);
    }
  }
  cout << res << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  int t = 1;
  while (t--) solve();
  return 0;
}