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 N = 1e5 + 500;
inline int read() {
  char ch;
  while ((ch = getchar()) < '0' || ch > '9')
    ;
  int res = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0';
  return res;
}
struct node {
  int x, q, r;
} d[N];
bool cmp(node a, node b) { return a.r > b.r; }
long long ans;
struct que {
  int x, y, w;
  que(int xx = 0, int yy = 0, int ww = 0) { x = xx, y = yy, w = ww; }
} q[N * 5], fz[N * 5];
int n, mq, K, px[N * 3];
struct Tree {
  long long d[N * 3];
  int lowbit(int x) { return x & -x; }
  long long sum(int x) {
    long long res = 0;
    for (int i = x; i; i -= lowbit(i)) res += d[i];
    return res;
  }
  void upt(int x, int v) {
    for (int i = x; i <= mq; i += lowbit(i)) d[i] += v;
  }
} T;
void solve(int l, int r) {
  if (l == r) return;
  int mid = l + r >> 1;
  solve(l, mid);
  solve(mid + 1, r);
  int p = l, p1 = l, p2 = mid + 1;
  while (p1 <= mid && p2 <= r) {
    if (q[p1].x <= q[p2].x) {
      if (q[p1].w == 0) T.upt(q[p1].y, 1);
      fz[p++] = q[p1++];
    } else {
      if (q[p2].w != 0) ans += T.sum(q[p2].y) * q[p2].w;
      fz[p++] = q[p2++];
    }
  }
  int pp = p1 - 1;
  while (p1 <= mid) fz[p++] = q[p1++];
  while (p2 <= r) {
    if (q[p2].w != 0) ans += T.sum(q[p2].y) * q[p2].w;
    fz[p++] = q[p2++];
  }
  for (int i = l; i <= pp; i++)
    if (!q[i].w) T.upt(q[i].y, -1);
  for (int i = l; i <= r; i++) q[i] = fz[i];
}
int main() {
  n = read();
  K = read();
  int x, r, zs;
  for (int i = 1; i <= n; i++) {
    x = read();
    r = read();
    zs = read();
    d[i] = (node){x, zs, r};
    px[++px[0]] = zs;
    px[++px[0]] = zs - K - 1;
    px[++px[0]] = zs + K;
  }
  sort(d + 1, d + 1 + n, cmp);
  sort(px + 1, px + 1 + px[0]);
  mq = unique(px + 1, px + 1 + px[0]) - px - 1;
  int qtot = 0;
  for (int i = 1; i <= n; i++) {
    int nq, lq, rq;
    nq = lower_bound(px + 1, px + 1 + mq, d[i].q) - px;
    lq = lower_bound(px + 1, px + 1 + mq, d[i].q - K - 1) - px;
    rq = lower_bound(px + 1, px + 1 + mq, d[i].q + K) - px;
    q[++qtot] = que(d[i].x - d[i].r - 1, rq, -1);
    q[++qtot] = que(d[i].x + d[i].r, lq, -1);
    q[++qtot] = que(d[i].x - d[i].r - 1, lq, 1);
    q[++qtot] = que(d[i].x + d[i].r, rq, 1);
    q[++qtot] = que(d[i].x, nq, 0);
  }
  solve(1, qtot);
  printf("%lld", ans);
  return 0;
}