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 maxn = (int)1e5 + 10;
vector<int> p[maxn];
vector<int> t[maxn];
int x[maxn], r[maxn], q[maxn];
int id[maxn];
bool cmp(int a, int b) { return r[a] < r[b]; }
void change(int it, int pos) {
  for (; pos < (int)t[it].size(); pos |= pos + 1) {
    t[it][pos]++;
  }
}
int getsum(int it, int pos) {
  int ans = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
    ans += t[it][pos];
  }
  return ans;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> z;
  for (int i = 0; i < n; i++) {
    id[i] = i;
    scanf("%d %d %d", &x[i], &r[i], &q[i]);
    z.push_back(q[i]);
  }
  sort(z.begin(), z.end());
  z.resize(unique(z.begin(), z.end()) - z.begin());
  for (int i = 0; i < n; i++) {
    int ps = lower_bound(z.begin(), z.end(), q[i]) - z.begin();
    p[ps].push_back(x[i]);
  }
  for (int i = 0; i < (int)z.size(); i++) {
    sort(p[i].begin(), p[i].end());
    t[i].resize(p[i].size());
  }
  sort(id, id + n, cmp);
  long long ans = 0;
  for (int ii = 0; ii < n; ii++) {
    int i = id[ii];
    int ps = lower_bound(z.begin(), z.end(), q[i]) - z.begin();
    for (int j = ps; j < (int)z.size(); j++) {
      if (z[j] - z[ps] > k) {
        break;
      }
      int rm =
          upper_bound(p[j].begin(), p[j].end(), x[i] + r[i]) - p[j].begin();
      int lm =
          lower_bound(p[j].begin(), p[j].end(), x[i] - r[i]) - p[j].begin();
      rm--;
      lm--;
      ans += rm - lm - (getsum(j, rm) - getsum(j, lm));
    }
    for (int j = ps - 1; j >= 0; j--) {
      if (z[ps] - z[j] > k) {
        break;
      }
      int rm =
          upper_bound(p[j].begin(), p[j].end(), x[i] + r[i]) - p[j].begin();
      int lm =
          lower_bound(p[j].begin(), p[j].end(), x[i] - r[i]) - p[j].begin();
      rm--;
      lm--;
      ans += rm - lm - (getsum(j, rm) - getsum(j, lm));
    }
    int rm = lower_bound(p[ps].begin(), p[ps].end(), x[i]) - p[ps].begin();
    change(ps, rm);
  }
  cout << ans - n << endl;
}