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>
const long long md = 1e9 + 7;
const int Inf = 1e9;
const long long Inf64 = 1e18;
const long long MaxN = 2e5 + 10;
const long long MaxM = 11;
const long double eps = 1e-15;
const long long dx[4] = {0, 1, 0, -1};
const long long dy[4] = {1, 0, -1, 0};
const long long ddx[4] = {1, 1, -1, -1};
const long long ddy[4] = {1, -1, 1, -1};
const long double Pi = acos(-1);
using namespace std;
long long gcd(long long a, long long b) {
  while (a) {
    b %= a;
    swap(a, b);
  }
  return b;
}
long long gcdex(long long a, long long mod = md) {
  long long g = mod, r = a, x = 0, y = 1;
  while (r != 0) {
    long long q = g / r;
    g %= r;
    swap(g, r);
    x -= q * y;
    swap(x, y);
  }
  return x < 0 ? x + mod : x;
}
long long binpow(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res *= a;
      res %= md;
    }
    a *= a;
    a %= md;
    n >>= 1;
  }
  return res % md;
}
struct el {
  long long x, r, q;
};
vector<long long> pos;
el Rb[MaxN];
map<long long, long long> Tree[4 * MaxN];
long long calc(map<long long, long long>& Mp, long long lq, long long rq) {
  auto it = Mp.lower_bound(lq);
  long long res = 0;
  while (it != Mp.end() && it->first <= rq) {
    res += it->second;
    it++;
  }
  return res;
}
long long getSum(long long l, long long r, long long x, long long y,
                 long long lq, long long rq, long long id) {
  if (x <= l && r <= y) {
    return calc(Tree[id], lq, rq);
  }
  long long mid = (l + r) >> 1;
  long long res = 0;
  if (x <= mid) res += getSum(l, mid, x, y, lq, rq, 2 * id + 1);
  if (mid < y) res += getSum(mid + 1, r, x, y, lq, rq, 2 * id + 2);
  return res;
}
void insert(long long l, long long r, long long x, long long a, long long id) {
  Tree[id][a]++;
  if (l == r) {
    return;
  } else {
    long long mid = (l + r) / 2;
    if (mid >= x) {
      insert(l, mid, x, a, 2 * id + 1);
    } else {
      insert(mid + 1, r, x, a, 2 * id + 2);
    }
  }
}
long long N, K;
long long getL(long long x) {
  long long l = 0, r = pos.size() - 1;
  int res = -1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (pos[mid] >= x) {
      res = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  return res;
}
long long getR(long long x) {
  long long l = 0, r = pos.size() - 1;
  long long res = -1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (pos[mid] <= x) {
      res = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return res;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  cout << fixed, cout.precision(10);
  cin >> N >> K;
  pos.assign(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> Rb[i].x >> Rb[i].r >> Rb[i].q;
    pos[i] = Rb[i].x;
  }
  sort(pos.begin(), pos.end());
  long long m = unique(pos.begin(), pos.end()) - pos.begin();
  pos.resize(m);
  sort(Rb, Rb + N, [=](el a, el b) { return a.r > b.r; });
  long long Ans = 0;
  for (int i = 0; i < N; i++) {
    long long l = getL(Rb[i].x - Rb[i].r);
    long long r = getR(Rb[i].x + Rb[i].r);
    l = max(l, 0LL);
    r = min(r, (long long)pos.size() - 1);
    Ans += getSum(0, pos.size() - 1, l, r, Rb[i].q - K, Rb[i].q + K, 0);
    long long x = getR(Rb[i].x);
    insert(0, pos.size() - 1, x, Rb[i].q, 0);
  }
  cout << Ans;
  cerr << '\n'
       << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec"
       << '\n';
  return 0;
}