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 = 1e5;
int n, kk, tot;
int xi[maxn + 5], ri[maxn + 5], qi[maxn + 5], num[maxn + 5];
int id[maxn + 5], inv[maxn + 5];
int L[maxn + 5], R[maxn + 5];
int sq[maxn + 5];
int tr[maxn + 5];
void Add(int x, int d) {
  for (; x <= n; x += x & (-x)) tr[x] += d;
}
int Sum(int x) {
  int r = 0;
  for (; x; x -= x & (-x)) r += tr[x];
  return r;
}
bool cmp(const int &a, const int &b) {
  if (qi[a] != qi[b]) return qi[a] < qi[b];
  return xi[a] < xi[b];
}
bool cmp2(const int &a, const int &b) { return ri[a] < ri[b]; }
int main() {
  scanf("%d%d", &n, &kk);
  tot = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", xi + i, ri + i, qi + i);
    num[i] = i;
    sq[++tot] = qi[i];
    L[tot] = 1 << 30, R[tot] = -L[tot];
  }
  sort(sq + 1, sq + 1 + tot);
  tot = unique(sq + 1, sq + 1 + tot) - sq - 1;
  sort(num + 1, num + 1 + n, cmp);
  for (int i = 1; i <= n; ++i) {
    id[num[i]] = i, inv[i] = num[i];
    int rk = lower_bound(sq + 1, sq + 1 + tot, qi[num[i]]) - sq;
    L[rk] = min(L[rk], i);
    R[rk] = max(R[rk], i);
    Add(i, 1);
  }
  sort(num + 1, num + 1 + n, cmp2);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int lrk = lower_bound(sq + 1, sq + 1 + tot, qi[num[i]] - kk) - sq;
    int rrk = upper_bound(sq + 1, sq + 1 + tot, qi[num[i]] + kk) - sq - 1;
    Add(id[num[i]], -1);
    for (int k = lrk; k <= rrk; ++k) {
      int l = L[k], r = R[k], psl = r + 1;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (xi[num[i]] - ri[num[i]] <= xi[inv[mid]])
          psl = mid, r = mid - 1;
        else
          l = mid + 1;
      }
      l = L[k], r = R[k];
      int psr = l - 1;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (xi[num[i]] + ri[num[i]] >= xi[inv[mid]])
          psr = mid, l = mid + 1;
        else
          r = mid - 1;
      }
      if (psl > psr) continue;
      ans += Sum(psr) - Sum(psl - 1);
    }
  }
  printf("%lld\n", ans);
  return 0;
}