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;
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline int qread() {
  register char c =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
           ? EOF
           : *p1++);
  register int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - 48;
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
  }
  return x * f;
}
inline int Abs(const int& x) { return (x > 0 ? x : -x); }
inline int Max(const int& x, const int& y) { return (x > y ? x : y); }
inline int Min(const int& x, const int& y) { return (x < y ? x : y); }
struct Bot {
  int x, r, q;
  bool operator<(const Bot& b) const { return q < b.q; }
};
struct Opt {
  int type, x, yl, yr;
  Opt() {}
  Opt(int type, int x, int yl, int yr) : type(type), x(x), yl(yl), yr(yr) {}
};
Opt opt[500005], tmp[500005];
int n, k, q, vtop, c[1500005];
long long ans = 0, val[1500005];
Bot a[100005];
int top = 0;
inline void Read() {
  n = qread();
  k = qread();
  for (int i = 1; i <= n; i++) {
    a[i].x = qread();
    a[i].r = qread();
    a[i].q = qread();
  }
}
inline void Prefix() {
  int l = 1, r = 1;
  for (int i = 1; i <= n; i++) {
    while (r <= n && a[r].q <= a[i].q + k) {
      opt[++q] = Opt(1, a[r].x - a[r].r, a[r].x, a[r].x);
      opt[++q] = Opt(-1, a[r].x + a[r].r + 1, a[r].x, a[r].x);
      r++;
    }
    while (l <= n && a[l].q < a[i].q - k) {
      opt[++q] = Opt(-1, a[l].x - a[l].r, a[l].x, a[l].x);
      opt[++q] = Opt(1, a[l].x + a[l].r + 1, a[l].x, a[l].x);
      l++;
    }
    opt[++q] = Opt(0, a[i].x, a[i].x - a[i].r, a[i].x + a[i].r);
  }
  for (int i = 1; i <= q; i++) {
    val[i] = opt[i].yl;
    val[i + q] = opt[i].yr;
    val[i + 2 * q] = opt[i].x;
  }
  sort(val + 1, val + 3 * q + 1);
  vtop = unique(val + 1, val + 3 * q + 1) - val - 1;
  for (int i = 1; i <= q; i++) {
    opt[i].yl = lower_bound(val + 1, val + vtop + 1, opt[i].yl) - val;
    opt[i].yr = lower_bound(val + 1, val + vtop + 1, opt[i].yr) - val;
    opt[i].x = lower_bound(val + 1, val + vtop + 1, opt[i].x) - val;
  }
}
inline int Lowbit(int x) { return x & -x; }
inline void Update(int i, int x) {
  for (int j = i; j <= vtop; j += Lowbit(j)) c[j] += x;
}
inline int Query(int i) {
  int ans = 0;
  for (int j = i; j >= 1; j -= Lowbit(j)) ans += c[j];
  return ans;
}
inline void Clear(int i) {
  for (int j = i; j <= vtop; j += Lowbit(j)) {
    if (!c[j]) break;
    c[j] = 0;
  }
}
inline void Cdq(int l, int r) {
  if (l == r) return;
  int mid = l + r >> 1;
  Cdq(l, mid);
  Cdq(mid + 1, r);
  int i = l, j = mid + 1, k = l;
  while (i <= mid && j <= r) {
    if (opt[i].x <= opt[j].x) {
      if (opt[i].type) Update(opt[i].yl, opt[i].type);
      tmp[k++] = opt[i++];
    } else {
      if (!opt[j].type) ans += Query(opt[j].yr) - Query(opt[j].yl - 1);
      tmp[k++] = opt[j++];
    }
  }
  while (i <= mid) {
    if (opt[i].type) Update(opt[i].yl, opt[i].type);
    tmp[k++] = opt[i++];
  }
  while (j <= r) {
    if (!opt[j].type) ans += Query(opt[j].yr) - Query(opt[j].yl - 1);
    tmp[k++] = opt[j++];
  }
  for (int i = l; i <= mid; i++) Clear(opt[i].yl);
  for (int i = l; i <= r; i++) opt[i] = tmp[i];
}
int main() {
  Read();
  sort(a + 1, a + n + 1);
  Prefix();
  Cdq(1, q);
  printf("%lld", (ans - n) / 2);
  return 0;
}