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;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int N = 100010;
struct rbt {
  int x, r, q, L, R;
  bool operator<(const rbt& rhs) const { return r < rhs.r; }
} a[N];
struct node {
  int a, b, x, y, opt;
  node(int A = 0, int B = 0, int C = 0, int D = 0, int E = 0) {
    a = A;
    b = B;
    x = C;
    y = D;
    opt = E;
  }
  bool operator<(const node& rhs) const {
    if (b == rhs.b) return opt > rhs.opt;
    return b < rhs.b;
  }
} p[N * 3], q[N * 3];
int n, k, len, f[N], num;
long long ans;
struct BIT {
  int c[N];
  inline int lb(int x) { return x & -x; }
  inline void change(int x, int y) {
    for (; x <= len; x += lb(x)) c[x] += y;
  }
  inline int query(int x) {
    int ans = 0;
    for (; x; x -= lb(x)) ans += c[x];
    return ans;
  }
} tree;
inline void solve(int l, int r) {
  if (l == r) return;
  int mid = l + r >> 1;
  solve(l, mid);
  solve(mid + 1, r);
  int x = l, y = mid + 1;
  for (int i = l; i <= r; ++i) {
    if ((x <= mid && p[x] < p[y]) || y > r) {
      if (p[x].opt == 2) tree.change(p[x].x, 1);
      q[i] = p[x++];
    } else {
      if (p[y].opt != 2)
        ans += p[y].opt * (tree.query(p[y].y) - tree.query(p[y].x));
      q[i] = p[y++];
    }
  }
  for (int i = l; i <= mid; ++i)
    if (p[i].opt == 2) tree.change(p[i].x, -1);
  for (int i = l; i <= r; ++i) p[i] = q[i];
}
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; ++i) {
    a[i].x = read();
    a[i].r = read();
    a[i].q = read();
    f[i] = a[i].q;
  }
  f[n + 1] = 0x7f7f7f7f;
  sort(f + 1, f + n + 2);
  len = unique(f + 1, f + n + 2) - f - 1;
  for (int i = 1; i <= n; ++i) {
    a[i].L = lower_bound(f + 1, f + len + 1, a[i].q - k) - f - 1;
    a[i].R = upper_bound(f + 1, f + len + 1, a[i].q + k) - f - 1;
    a[i].q = lower_bound(f + 1, f + len + 1, a[i].q) - f;
  }
  sort(a + 1, a + n + 1);
  for (int i = n; i >= 1; --i) {
    p[++num] = node(num, a[i].x - a[i].r - 1, a[i].L, a[i].R, -1);
    p[++num] = node(num, a[i].x + a[i].r, a[i].L, a[i].R, 1);
    p[++num] = node(num, a[i].x, a[i].q, a[i].q, 2);
  }
  solve(1, num);
  printf("%lld", ans);
  return 0;
}