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 long long maxn = 1e5 + 5, maxm = 1005;
inline void chkmin(long long &x, long long y) { x = x < y ? x : y; }
inline long long read() {
  char c = getchar();
  long long ans = 0, f = 0;
  for (; c < '0' || c > '9'; c = getchar()) f |= (c == '-');
  for (; c >= '0' && c <= '9'; c = getchar()) (ans *= 10) += c - '0';
  return f ? -ans : ans;
}
struct node {
  long long x, r, q;
} arr[maxn << 1];
long long bx[maxn << 1], bq[maxn << 1], mx, mq;
bool cmp(node a, node b) { return a.r > b.r; }
long long n, k;
long long tot;
struct segment_tree {
  long long ls, rs, sum;
} tree[maxn << 5];
void insert(long long &p, long long l, long long r, long long x) {
  if (!p) p = ++tot;
  tree[p].sum++;
  if (l < r) {
    long long mid = l + r >> 1;
    if (x <= mid)
      insert(tree[p].ls, l, mid, x);
    else
      insert(tree[p].rs, mid + 1, r, x);
  }
}
long long query(long long p, long long l, long long r, long long L,
                long long R) {
  if (!p) return 0;
  if (L <= l && r <= R) return tree[p].sum;
  long long sum = 0, mid = l + r >> 1;
  if (L <= mid) sum += query(tree[p].ls, l, mid, L, R);
  if (mid < R) sum += query(tree[p].rs, mid + 1, r, L, R);
  return sum;
}
long long rt[maxn];
int main() {
  n = read(), k = read();
  for (long long i = 1; i <= n; i++) {
    arr[i] = (node){read(), read(), read()};
    bx[i] = arr[i].x;
    bq[i] = arr[i].q;
  }
  sort(bx + 1, bx + n + 1);
  mx = unique(bx + 1, bx + n + 1) - bx - 1;
  sort(bq + 1, bq + n + 1);
  mq = unique(bq + 1, bq + n + 1) - bq - 1;
  sort(arr + 1, arr + n + 1, cmp);
  long long ans = 0;
  for (long long i = 1, x, q, l, r, L, R; i <= n; i++) {
    x = lower_bound(bx + 1, bx + mx + 1, arr[i].x) - bx;
    l = lower_bound(bx + 1, bx + mx + 1, arr[i].x - arr[i].r) - bx;
    r = lower_bound(bx + 1, bx + mx + 1, arr[i].x + arr[i].r + 1) - bx - 1;
    q = lower_bound(bq + 1, bq + mq + 1, arr[i].q) - bq;
    L = lower_bound(bq + 1, bq + mq + 1, arr[i].q - k) - bq;
    R = lower_bound(bq + 1, bq + mq + 1, arr[i].q + k + 1) - bq - 1;
    for (long long j = L; j <= R; j++) {
      ans += query(rt[j], 1, mx, l, r);
    }
    insert(rt[q], 1, mx, x);
  }
  printf("%lld\n", ans);
  return 0;
}