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>
const int M = 200005;
const int INF = 1e9;
const double alp = 0.8;
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0, w = 1;
  while (c > '9' || c < '0') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * w;
}
int n, m, K;
int top, st[M], tot, rtp;
long long ans;
struct Poi {
  int x[2];
} p[M];
struct Person {
  int x, r, q;
} pi[M];
struct Node {
  Poi tp;
  int lsn, rsn, sz, tmi[2], tmx[2];
} t[M];
inline bool operator<(Person a, Person b) { return a.r > b.r; }
inline bool operator<(Poi a, Poi b) { return a.x[K] < b.x[K]; }
inline int New() { return ++tot; }
inline void pushup(int now) {
  for (int k = 0; k <= 1; k++) {
    t[now].tmi[k] = t[now].tmx[k] = t[now].tp.x[k];
    if (t[now].lsn) {
      t[now].tmi[k] = min(t[now].tmi[k], t[t[now].lsn].tmi[k]);
      t[now].tmx[k] = max(t[now].tmx[k], t[t[now].lsn].tmx[k]);
    }
    if (t[now].rsn) {
      t[now].tmi[k] = min(t[now].tmi[k], t[t[now].rsn].tmi[k]);
      t[now].tmx[k] = max(t[now].tmx[k], t[t[now].rsn].tmx[k]);
    }
  }
  t[now].sz = t[t[now].lsn].sz + t[t[now].rsn].sz + 1;
}
int build(int l, int r, int W) {
  if (l > r) return 0;
  K = W;
  int cnt = New(), mid = (l + r) >> 1;
  nth_element(p + l, p + mid, p + r + 1);
  t[cnt].tp = p[mid];
  t[cnt].lsn = build(l, mid - 1, (W ^ 1));
  t[cnt].rsn = build(mid + 1, r, (W ^ 1));
  pushup(cnt);
  return cnt;
}
void Ins(Poi po, int &now, int W) {
  if (!now) {
    now = New();
    t[now].tp = po;
    pushup(now);
    return;
  }
  if (po.x[W] <= t[now].tp.x[W])
    Ins(po, t[now].lsn, (W ^ 1));
  else
    Ins(po, t[now].rsn, (W ^ 1));
  pushup(now);
}
inline bool Allin(int ax, int ay, int bx, int by, int Ax, int Ay, int Bx,
                  int By) {
  return (Ax >= ax && Ay >= ay && Bx <= bx && By <= by);
}
inline bool Allout(int ax, int ay, int bx, int by, int Ax, int Ay, int Bx,
                   int By) {
  return (Ax > bx || Ay > by || Bx < ax || By < ay);
}
int query(int lx, int ly, int rx, int ry, int now) {
  if (!now) return 0;
  if (Allin(lx, ly, rx, ry, t[now].tmi[0], t[now].tmi[1], t[now].tmx[0],
            t[now].tmx[1]))
    return t[now].sz;
  if (Allout(lx, ly, rx, ry, t[now].tmi[0], t[now].tmi[1], t[now].tmx[0],
             t[now].tmx[1]))
    return 0;
  int ret = 0;
  if (Allin(lx, ly, rx, ry, t[now].tp.x[0], t[now].tp.x[1], t[now].tp.x[0],
            t[now].tp.x[1]))
    ret++;
  ret += query(lx, ly, rx, ry, t[now].lsn) + query(lx, ly, rx, ry, t[now].rsn);
  return ret;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) {
    pi[i].x = read();
    pi[i].r = read();
    pi[i].q = read();
  }
  sort(pi + 1, pi + n + 1);
  Poi po;
  for (int i = 1; i <= n; i++) {
    ans += query(pi[i].x - pi[i].r, pi[i].q - m, pi[i].x + pi[i].r, pi[i].q + m,
                 rtp);
    p[i].x[0] = pi[i].x;
    p[i].x[1] = pi[i].q;
    Ins(p[i], rtp, 0);
    if (i % 5001 == 0) {
      tot = 0;
      rtp = build(1, i, 0);
    }
  }
  printf("%lld\n", ans);
  return 0;
}