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 N = 1e5 + 10;
struct node {
  int x, r, q;
} d[N];
bool operator<(const node& a, const node& b) { return a.r > b.r; }
int root[N * 33], sum[N * 33], lrt[N * 33], rrt[N * 33], cnt;
vector<int> v;
int get_id(int x) { return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; }
void update(int x, int l, int r, int& rt) {
  if (!rt) rt = ++cnt;
  sum[rt]++;
  if (l == r) return;
  int m = l + r >> 1;
  if (x <= m)
    update(x, l, m, lrt[rt]);
  else
    update(x, m + 1, r, rrt[rt]);
}
int query(int L, int R, int l, int r, int rt) {
  if (!rt) return 0;
  if (l >= L && r <= R) return sum[rt];
  int res = 0;
  int m = l + r >> 1;
  if (L <= m) res += query(L, R, l, m, lrt[rt]);
  if (R > m) res += query(L, R, m + 1, r, rrt[rt]);
  return res;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> d[i].x >> d[i].r >> d[i].q;
    v.push_back(d[i].q);
    v.push_back(max(0, d[i].q - k));
    v.push_back(d[i].q + k);
  }
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  sort(d, d + n);
  int mx = 1e9;
  long long res = 0;
  for (int i = 0; i < n; i++) {
    int l = get_id(max(0, d[i].q - k)), r = get_id(d[i].q + k);
    for (int j = l; j <= r; j++) {
      if (!root[j]) continue;
      res += query(max(0, d[i].x - d[i].r), d[i].x + d[i].r, 0, mx, root[j]);
    }
    update(d[i].x, 0, mx, root[get_id(d[i].q)]);
  }
  cout << res << '\n';
  return 0;
}