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;
const int inf = 0x3f3f3f3f;
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 << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int die = 0;
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int N1 = 1e6 + 5;
const int N2 = 1e5 + 5;
int n, k;
struct node {
  int x, l, r, R, q;
} e[N1];
long long ans = 0;
int tr[N1];
int b[N1];
int co;
void ins(int x, int d) {
  for (; x <= co; x += x & -x) tr[x] += d;
}
long long ask(int x) {
  long long ans = 0;
  for (; x; x &= x - 1) ans += tr[x];
  return ans;
}
void cdq(int l, int r) {
  if (l == r) return;
  int mid = l + (r - l) / 2;
  cdq(l, mid), cdq(mid + 1, r);
  int j1 = mid + 1, j2 = mid + 1;
  for (int i = (l); i <= (mid); i++) {
    while (j2 <= r && e[j2].q <= e[i].q + k) ins(e[j2].x, 1), j2++;
    while (j1 <= j2 - 1 && e[j1].q < e[i].q - k) ins(e[j1].x, -1), j1++;
    ans += ask(e[i].r) - ask(e[i].l - 1);
  }
  for (int j = (j1); j <= (j2 - 1); j++) ins(e[j].x, -1);
  inplace_merge(e + l, e + mid + 1, e + r + 1,
                [](node a, node b) { return a.q < b.q; });
}
void sol1() {
  int tot = 0;
  for (int i = (1); i <= (n); i++)
    b[++tot] = e[i].x, b[++tot] = e[i].l = max(0, e[i].x - e[i].R),
    b[++tot] = e[i].r = e[i].x + e[i].R;
  sort(b + 1, b + 1 + tot);
  co = unique(b + 1, b + 1 + tot) - b - 1;
  for (int i = (1); i <= (n); i++)
    e[i].x = lower_bound(b + 1, b + 1 + co, e[i].x) - b,
    e[i].l = lower_bound(b + 1, b + 1 + co, e[i].l) - b,
    e[i].r = lower_bound(b + 1, b + 1 + co, e[i].r) - b;
  sort(e + 1, e + 1 + n, [](node a, node b) { return a.R < b.R; });
  cdq(1, n);
  cout << ans;
}
void rd() {
  n = read(), k = read();
  for (int i = (1); i <= (n); i++)
    e[i].x = read(), e[i].R = read(), e[i].q = read();
  sol1();
}
signed main() { rd(); }