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;
template <typename T>
inline T rd() {
  T nmb = 0;
  int sgn = 0;
  char chr = getchar();
  while (!isdigit(chr)) {
    if (chr == '-') sgn = 1;
    chr = getchar();
  }
  while (isdigit(chr)) {
    nmb = (nmb << 3) + (nmb << 1) + chr - '0';
    chr = getchar();
  }
  return sgn ? -nmb : nmb;
}
template <typename T>
void wt(T nmb) {
  if (nmb > 9) wt(nmb / 10);
  putchar(nmb % 10 + '0');
}
template <typename T>
inline void cmax(T &x, T y) {
  x = x > y ? x : y;
}
template <typename T>
inline void cmin(T &x, T y) {
  x = x < y ? x : y;
}
const int N = 1e5 + 10;
int n, p;
struct node {
  int x, r, q;
} a[N];
inline int Cmp(node u, node v) { return u.r > v.r; }
inline int cmp(node u, node v) { return u.q < v.q; }
int buc[N], num;
int val[N];
inline int lowbit(int x) { return x & (-x); }
inline void add(int x, int p) {
  for (; x <= num; x += lowbit(x)) val[x] += p;
}
inline int query(int x) {
  int res = 0;
  for (; x > 0; x ^= lowbit(x)) res += val[x];
  return res;
}
long long ans;
void divide(int l, int r) {
  if (l == r) return;
  int m = (l + r) >> 1;
  divide(l, m);
  divide(m + 1, r);
  sort(a + l, a + m + 1, cmp), sort(a + m + 1, a + r + 1, cmp);
  int lft = l, rgt = l;
  for (int i = m + 1; i <= r; ++i) {
    while (lft <= m && a[lft].q < a[i].q - p) add(a[lft].x, -1), ++lft;
    while (rgt <= m && a[rgt].q <= a[i].q + p) add(a[rgt].x, 1), ++rgt;
    int L = lower_bound(buc + 1, buc + num + 1, buc[a[i].x] - a[i].r) - buc;
    int R = upper_bound(buc + 1, buc + num + 1, buc[a[i].x] + a[i].r) - buc - 1;
    ans += query(R) - query(L - 1);
  }
  while (lft < rgt) add(a[lft].x, -1), ++lft;
}
int main() {
  n = rd<int>(), p = rd<int>();
  for (int i = 1; i <= n; ++i)
    a[i] = (node){rd<int>(), rd<int>(), rd<int>()}, buc[i] = a[i].x;
  sort(buc + 1, buc + n + 1);
  num = unique(buc + 1, buc + n + 1) - buc - 1;
  for (int i = 1; i <= n; ++i)
    a[i].x = lower_bound(buc + 1, buc + num + 1, a[i].x) - buc;
  sort(a + 1, a + n + 1, Cmp);
  divide(1, n);
  printf("%lld\n", ans);
  return 0;
}