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>
static const int N = 1 << 17;
struct Fenwick {
  int n;
  int t[N * 4];
  void set(int n) { this->n = n; }
  void add(int x, int v) {
    for (int i = x; i <= n; i += (i & -i)) t[i] += v;
  }
  void clear(int x) {
    for (int i = x; i <= n; i += (i & -i)) t[i] = 0;
  }
  int query(int x) {
    int ans = 0;
    for (int i = x; i > 0; i -= (i & -i)) ans += t[i];
    return ans;
  }
  int query(int l, int r) { return query(r) - query(l - 1); }
} fenwick;
int readInt() {
  int x = 0, f = 1;
  int c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
struct node {
  long long x, R, l, r, q;
  bool operator<(node const& o) const { return R < o.R; }
} s[N];
bool cmp(const node& a, const node& b) { return a.q < b.q; }
long long ans;
int n, k, cc;
long long d[N * 4];
void merge(int l, int r) {
  if (l == r) return;
  int m = (l + r) >> 1;
  merge(l, m);
  merge(m + 1, r);
  int st = m + 1, e = m;
  for (int i = l; i <= m; ++i) {
    while (e < r && s[e + 1].q <= s[i].q + k) {
      ++e;
      fenwick.add(s[e].x, +1);
    }
    while (st <= e && s[st].q < s[i].q - k) {
      fenwick.add(s[st].x, -1);
      ++st;
    }
    ans += fenwick.query(s[i].l, s[i].r);
  }
  for (int i = m + 1; i <= r; ++i) fenwick.clear(s[i].x);
  std::inplace_merge(s + l, s + m + 1, s + r + 1, cmp);
}
int solve() {
  n = readInt();
  k = readInt();
  cc = 0;
  for (int i = 1; i <= n; ++i) {
    s[i].x = readInt();
    s[i].R = readInt();
    s[i].q = readInt();
    d[cc++] = s[i].x;
    d[cc++] = s[i].x - s[i].R;
    d[cc++] = s[i].x + s[i].R;
  }
  std::sort(d, d + cc);
  cc = std::unique(d, d + cc) - d;
  for (int i = 1; i <= n; ++i) {
    s[i].l = std::lower_bound(d, d + cc, s[i].x - s[i].R) - d;
    s[i].r = std::lower_bound(d, d + cc, s[i].x + s[i].R) - d;
    s[i].x = std::lower_bound(d, d + cc, s[i].x) - d;
    ++s[i].l;
    ++s[i].r;
    ++s[i].x;
  }
  std::sort(s + 1, s + n + 1);
  fenwick.set(cc);
  ans = 0;
  merge(1, n);
  printf("%lld\n", ans);
  return 0;
}
int main(int argc, char* argv[]) { solve(); }