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>
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int N = 1e5 + 7;
const int INF = 1e9 + 7;
int t[4 * N], tsp[4 * N];
int lf[N], rf[N], pos[N];
int n, k, sp;
long long ans;
struct rb {
  int x, r, iq;
} a[N];
vector<int> b;
bool comp(rb a, rb b) {
  if (a.iq == b.iq) return a.r < b.r;
  return a.iq < b.iq;
}
bool comp2(int i, int j) {
  if (i == 0) return true;
  if (j == 0) return false;
  return a[i].x < a[j].x;
}
bool comp3(int i, int j) {
  if (i == 0) return true;
  if (j == 0) return false;
  return a[i].r < a[j].r;
}
void build(int v, int l, int r) {
  if (l == r) {
    tsp[v] = 0;
    if (a[b[l]].iq == sp) tsp[v] = 1;
    t[v] = 1;
  } else {
    int mid = (l + r) >> 1;
    build(v + v, l, mid);
    build(v + v + 1, mid + 1, r);
    t[v] = t[v + v] + t[v + v + 1];
    tsp[v] = tsp[v + v] + tsp[v + v + 1];
  }
}
void upd(int v, int l, int r, int pos) {
  if (l == r)
    t[v] = tsp[v] = 0;
  else {
    int mid = (l + r) >> 1;
    if (pos <= mid)
      upd(v + v, l, mid, pos);
    else
      upd(v + v + 1, mid + 1, r, pos);
    t[v] = t[v + v] + t[v + v + 1];
    tsp[v] = tsp[v + v] + tsp[v + v + 1];
  }
}
int get1(int v, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return t[v];
  if (r < ql || qr < l) return 0;
  int mid = (l + r) >> 1;
  return get1(v + v, l, mid, ql, qr) + get1(v + v + 1, mid + 1, r, ql, qr);
}
int get2(int v, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return tsp[v];
  if (r < ql || qr < l) return 0;
  int mid = (l + r) >> 1;
  return get2(v + v, l, mid, ql, qr) + get2(v + v + 1, mid + 1, r, ql, qr);
}
void solve(int l, int r) {
  b.push_back(0);
  int n = r - l + 1;
  for (int i = l; i <= r; i++) b.push_back(i);
  sort(b.begin(), b.end(), comp2);
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    pos[b[i]] = i;
    int lb = 0, rb = i;
    while (lb + 1 < rb) {
      int mid = (lb + rb) >> 1;
      if (a[b[i]].x - a[b[mid]].x <= a[b[i]].r)
        rb = mid;
      else
        lb = mid;
    }
    lf[b[i]] = rb;
    lb = i, rb = n + 1;
    while (lb + 1 < rb) {
      int mid = (lb + rb) >> 1;
      if (a[b[mid]].x - a[b[i]].x <= a[b[i]].r)
        lb = mid;
      else
        rb = mid;
    }
    rf[b[i]] = lb;
  }
  sort(b.begin(), b.end(), comp3);
  for (int i = 1; i <= n; i++) {
    upd(1, 1, n, pos[b[i]]);
    if (a[b[i]].iq == sp)
      ans += get1(1, 1, n, lf[b[i]], rf[b[i]]);
    else
      ans += get2(1, 1, n, lf[b[i]], rf[b[i]]);
  }
  b.clear();
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) scanf("%d%d%d", &a[i].x, &a[i].r, &a[i].iq);
  sort(a + 1, a + n + 1, comp);
  int l = 1;
  a[n + 1].iq = INF;
  for (int i = 1; i <= n; i++) {
    if (a[i + 1].iq - a[l].iq > k) {
      sp = a[l].iq;
      solve(l, i);
      int t = l;
      while (a[l].iq == a[t].iq) l++;
      i--;
    }
  }
  cout << ans;
}