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>
#pragma GCC optimize("Ofast", "inline", "no-stack-protector")
using namespace std;
int rd() {
  int x;
  char c(getchar());
  bool k;
  while (!isdigit(c) && c ^ '-')
    if ((c = getchar()) == EOF) exit(0);
  c ^ '-' ? (k = 1, x = c & 15) : k = x = 0;
  while (isdigit((c = getchar()))) x = x * 10 + (c & 15);
  return k ? x : -x;
}
void wr(long long a) {
  if (a < 0) putchar('-'), a = -a;
  if (a <= 9)
    putchar(a | '0');
  else
    wr(a / 10), putchar((a % 10) | '0');
}
signed const INF(0x3f3f3f3f), NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL), LNINF(0xc3c3c3c3c3c3c3c3LL);
int n, k, d[(100010)], t[(100010)];
long long ans;
struct R {
  int x, r, q, i, p, lp, rp;
} a[(100010)];
void mdf(int x, int v) {
  while (x <= n) t[x] += v, x += x & -x;
}
int qry(int x) {
  int r(0);
  while (x) r += t[x], x ^= x & -x;
  return r;
}
void cdq(int l, int r);
signed main() {
  (n = rd()), (k = rd());
  for (int i(1); i <= (n); ++i) a[i] = {d[i] = rd(), rd(), rd(), i};
  sort(d + 1, d + n + 1),
      sort(a + 1, a + n + 1, [](R a, R b) { return a.r > b.r; });
  for (int i(1); i <= (n); ++i) {
    a[i].p = lower_bound(d + 1, d + n + 1, a[i].x) - d;
    a[i].lp = lower_bound(d + 1, d + n + 1, a[i].x - a[i].r) - d;
    a[i].rp = upper_bound(d + 1, d + n + 1, a[i].x + a[i].r) - d - 1;
  }
  cdq(1, n), wr(ans), exit(0);
}
void cdq(int l, int r) {
  if (l == r) return;
  int m((l + r) >> 1), p(l), q(l);
  cdq(l, m), cdq(m + 1, r);
  for (int i(m + 1); i <= (r); ++i) {
    while (q <= m && a[q].q - a[i].q <= k) mdf(a[q++].p, 1);
    while (p < q && a[i].q - a[p].q > k) mdf(a[p++].p, -1);
    ans += qry(a[i].rp) - qry(a[i].lp - 1);
  }
  for (int i(p); i < (q); ++i) mdf(a[i].p, -1);
  sort(a + l, a + r + 1, [](R a, R b) { return a.q < b.q; });
}