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;
using lint = long long;
const int MAXN = 100005;
const int mod = 1e9 + 7;
struct line {
  int x, r, k;
  bool operator<(const line &l) const { return r < l.r; }
} a[MAXN];
vector<int> x, k;
vector<int> elem[MAXN], bit[MAXN];
int query(vector<int> &v, vector<int> &w, int x) {
  x = upper_bound(w.begin(), w.end(), x) - w.begin() - 1;
  int ret = 0;
  while (x) {
    ret += v[x];
    x -= x & -x;
  }
  return ret;
}
void add(vector<int> &v, vector<int> &w, int x) {
  x = lower_bound(w.begin(), w.end(), x) - w.begin();
  while (x < v.size()) {
    v[x]++;
    x += x & -x;
  }
}
int n, K;
int ks[MAXN], ke[MAXN];
int xs[MAXN], xe[MAXN];
int main() {
  scanf("%d %d", &n, &K);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &a[i].x, &a[i].r, &a[i].k);
    x.push_back(a[i].x);
    k.push_back(a[i].k);
  }
  sort(a, a + n);
  sort(x.begin(), x.end());
  x.resize(unique(x.begin(), x.end()) - x.begin());
  sort(k.begin(), k.end());
  k.resize(unique(k.begin(), k.end()) - k.begin());
  for (int i = 0; i < n; i++) {
    xs[i] = lower_bound(x.begin(), x.end(), a[i].x - a[i].r) - x.begin();
    xe[i] =
        lower_bound(x.begin(), x.end(), a[i].x + a[i].r + 1) - x.begin() - 1;
    ks[i] = lower_bound(k.begin(), k.end(), a[i].k - K) - k.begin();
    ke[i] = lower_bound(k.begin(), k.end(), a[i].k + K + 1) - k.begin() - 1;
    a[i].x = lower_bound(x.begin(), x.end(), a[i].x) - x.begin();
    a[i].k = lower_bound(k.begin(), k.end(), a[i].k) - k.begin();
    elem[a[i].k].push_back(a[i].x + 1);
  }
  for (int i = 0; i < k.size(); i++) {
    elem[i].push_back(-1);
    sort(elem[i].begin(), elem[i].end());
    elem[i].resize(unique(elem[i].begin(), elem[i].end()) - elem[i].begin());
    bit[i].resize(elem[i].size());
  }
  lint ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = ks[i]; j <= ke[i]; j++) {
      ans += query(bit[j], elem[j], xe[i] + 1) - query(bit[j], elem[j], xs[i]);
    }
    add(bit[a[i].k], elem[a[i].k], a[i].x + 1);
  }
  cout << ans << endl;
}