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;
struct node {
  int x, r, q, id, op;
} s[500005], hc[500005];
struct lsh {
  int v, id;
} bk[500005];
int n, k, zbk, zz;
long long t[500005], f[500005];
bool cmp(node a, node b) {
  return a.x != b.x ? a.x < b.x : (a.q != b.q ? a.q < b.q : a.r < b.r);
}
bool cmp1(lsh a, lsh b) { return a.v != b.v ? a.v < b.v : a.id < b.id; }
void add(int p) {
  while (p <= zbk) {
    ++t[p];
    p += p & (-p);
  }
}
void clear(int p) {
  while (p <= zbk) {
    t[p] = 0;
    p += p & (-p);
  }
}
long long query(long long p) {
  long long ans = 0;
  while (p > 0) {
    ans += t[p];
    p -= p & (-p);
  }
  return ans;
}
void cdq(int l, int r) {
  if (l == r) return;
  int mid = l + r >> 1;
  cdq(l, mid);
  cdq(mid + 1, r);
  int p1 = l, p2 = mid + 1, np = l - 1;
  while (p1 <= mid && p2 <= r) {
    if (s[p1].q <= s[p2].q) {
      hc[++np] = s[p1];
      if (!s[p1].op) add(s[p1].r);
      ++p1;
    } else {
      hc[++np] = s[p2];
      if (s[p2].op) f[s[p2].id] += s[p2].op * query(s[p2].r);
      ++p2;
    }
  }
  while (p2 <= r) {
    hc[++np] = s[p2];
    if (s[p2].op) f[s[p2].id] += s[p2].op * query(s[p2].r);
    ++p2;
  }
  for (int i = l; i <= np; ++i) {
    if (!hc[i].op) clear(hc[i].r);
  }
  while (p1 <= mid) hc[++np] = s[p1], ++p1;
  for (int i = l; i <= r; ++i) s[i] = hc[i];
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    ++zz;
    scanf("%d%d%d", &s[zz].x, &s[zz].r, &s[zz].q);
    s[zz].id = i;
    s[zz + 1].x = s[zz].x + s[zz].r;
    s[zz + 1].q = s[zz].q + k;
    s[zz + 1].r = 1000000001 - s[zz].r;
    s[zz + 1].id = i;
    s[zz + 1].op = 1;
    s[zz + 2].x = s[zz].x - s[zz].r - 1;
    s[zz + 2].q = s[zz].q - k - 1;
    s[zz + 2].r = 1000000001 - s[zz].r;
    s[zz + 2].id = i;
    s[zz + 2].op = 1;
    s[zz + 3].x = s[zz].x - s[zz].r - 1;
    s[zz + 3].q = s[zz].q + k;
    s[zz + 3].r = 1000000001 - s[zz].r;
    s[zz + 3].id = i;
    s[zz + 3].op = -1;
    s[zz + 4].x = s[zz].x + s[zz].r;
    s[zz + 4].q = s[zz].q - k - 1;
    s[zz + 4].r = 1000000001 - s[zz].r;
    s[zz + 4].id = i;
    s[zz + 4].op = -1;
    s[zz].r = 1000000001 - s[zz].r;
    zz += 4;
  }
  for (int i = 1; i <= zz; i += 5) bk[++zbk].v = s[i].r, bk[zbk].id = i;
  sort(bk + 1, bk + 1 + zbk, cmp1);
  for (int a, i = 1; i <= zbk; ++i) {
    a = bk[i].id;
    s[a].r = s[a + 1].r = s[a + 2].r = s[a + 3].r = s[a + 4].r = i;
  }
  sort(s + 1, s + 1 + zz, cmp);
  cdq(1, zz);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) ans += f[i] - 1;
  printf("%lld", ans);
  return 0;
}