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 _ = 1e5 + 20;
struct Query {
  int l, r, x, q;
} a[_];
int cmp(Query x, Query y) { return x.x < y.x; }
int CMP(int *x, int *y) { return *x < *y; }
int n, k, *dis[_ << 3], cnt;
long long ans;
int operator<(Query x, Query y) { return x.r > y.r; }
priority_queue<Query> q;
map<int, int> m[_ << 3];
map<int, int>::iterator iter;
void insert(int y, int x) {
  iter = m[y].find(x);
  if (iter == m[y].end())
    m[y].insert(map<int, int>::value_type(x, 1));
  else
    iter->second++;
}
void Delete(int y, int x) {
  iter = m[y].find(x);
  iter->second--;
}
int query(int y, int x) {
  int s = 0;
  for (iter = m[y].lower_bound(x - k);
       iter != m[y].end() && iter->first <= x + k; ++iter)
    s += iter->second;
  return s;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    int x, r, q;
    cin >> x >> r >> q;
    a[i].l = x - r;
    a[i].r = x + r;
    a[i].x = x;
    a[i].q = q;
    dis[++cnt] = &a[i].l;
    dis[++cnt] = &a[i].r;
    dis[++cnt] = &a[i].x;
  }
  sort(dis + 1, dis + cnt + 1, CMP);
  int t = 0;
  for (int base = -2e9, i = 1; i <= cnt; ++i) {
    if (*dis[i] != base) t++, base = *dis[i];
    *dis[i] = t;
  }
  cnt = t;
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; ++i) {
    int k;
    while (!q.empty()) {
      Query c = q.top();
      if (c.r < a[i].x)
        q.pop();
      else
        break;
      k = c.x;
      Delete(0, c.q);
      while (k <= cnt) Delete(k, c.q), k += (k & -k);
    }
    ans += query(0, a[i].q);
    k = a[i].l - 1;
    while (k) ans -= query(k, a[i].q), k -= (k & -k);
    k = a[i].x;
    insert(0, a[i].q);
    while (k <= cnt) insert(k, a[i].q), k += (k & -k);
    q.push(a[i]);
  }
  cout << ans << endl;
  return 0;
}