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 T1, typename T2>
void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
namespace fastio {
char rbuf[1 << 23], *p1 = rbuf, *p2 = rbuf, wbuf[1 << 23], *p3 = wbuf;
inline char getc() {
  return p1 == p2 &&
                 (p2 = (p1 = rbuf) + fread(rbuf, 1, 1 << 23, stdin), p1 == p2)
             ? -1
             : *p1++;
}
inline void putc(char x) { (*p3++ = x); }
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  T neg = 0;
  while (!isdigit(c)) neg |= !(c ^ '-'), c = getchar();
  while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  if (neg) x = (~x) + 1;
}
template <typename T>
void recursive_print(T x) {
  if (!x) return;
  recursive_print(x / 10);
  putc(x % 10 ^ 48);
}
template <typename T>
void print(T x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = ~x + 1;
  recursive_print(x);
}
void print_final() { fwrite(wbuf, 1, p3 - wbuf, stdout); }
}  // namespace fastio
const int MAXN = 1e5;
int n, k, key[MAXN + 5], uni[MAXN + 5], num = 0;
struct robot {
  int x, len, q;
} a[MAXN + 5];
bool cmp1(robot lhs, robot rhs) { return lhs.len > rhs.len; }
bool cmp2(robot lhs, robot rhs) { return lhs.q < rhs.q; }
int t[MAXN + 5];
long long ans = 0;
void add(int x, int v) {
  for (int i = x; i <= num; i += (i & (-i))) t[i] += v;
}
int query(int x) {
  int ret = 0;
  for (int i = x; i; i &= (i - 1)) ret += t[i];
  return ret;
}
int query(int l, int r) { return query(r) - query(l - 1); }
void cdq(int l, int r) {
  if (l == r) return;
  int mid = l + r >> 1;
  cdq(l, mid);
  cdq(mid + 1, r);
  int pl = l, pr = l;
  for (int i = mid + 1; i <= r; i++) {
    while (a[pr].q <= a[i].q + k && pr <= mid) {
      int pos = lower_bound(uni + 1, uni + num + 1, a[pr].x) - uni;
      add(pos, 1);
      ++pr;
    }
    while (a[pl].q < a[i].q - k && pl <= mid) {
      int pos = lower_bound(uni + 1, uni + num + 1, a[pl].x) - uni;
      add(pos, -1);
      ++pl;
    }
    int l = lower_bound(uni + 1, uni + num + 1, a[i].x - a[i].len) - uni;
    int r = upper_bound(uni + 1, uni + num + 1, a[i].x + a[i].len) - uni - 1;
    ans += query(l, r);
  }
  for (int i = pl; i < pr; i++) {
    int pos = lower_bound(uni + 1, uni + num + 1, a[i].x) - uni;
    add(pos, -1);
  }
  sort(a + l, a + r + 1, cmp2);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &a[i].x, &a[i].len, &a[i].q);
    key[i] = a[i].x;
  }
  key[0] = -1;
  sort(key + 1, key + n + 1);
  sort(a + 1, a + n + 1, cmp1);
  for (int i = 1; i <= n; i++)
    if (key[i] ^ key[i - 1]) uni[++num] = key[i];
  cdq(1, n);
  printf("%lld\n", ans);
  return 0;
}