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;
long long n, k, co, p, r, iq, ans;
vector<long long> v, vec_q;
pair<long long, pair<long long, long long> > A[100006 * 3];
struct fen {
  vector<long long> v;
  vector<long long> fw;
  long long n = 0;
  fen() {
    v.clear();
    fw.clear();
    n = 0;
  }
  void add_elem(long long x) {
    v.push_back(x);
    n++;
  }
  void init() {
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    n = v.size();
    fw.resize(n + 2);
    for (long long i = 0; i < n + 2; i++) fw[0] = 0;
  }
  void update(long long x, long long nv) {
    x = lower_bound(v.begin(), v.end(), x) - v.begin();
    ++x;
    for (; x <= n; x += x & (-x)) fw[x] += nv;
  }
  long long sum(long long x) {
    long long res = 0;
    for (; x; x -= x & (-x)) res += fw[x];
    return res;
  }
  long long range_sum(long long a, long long b) {
    a = lower_bound(v.begin(), v.end(), a) - v.begin();
    if (a == v.size()) return 0;
    b = upper_bound(v.begin(), v.end(), b) - v.begin() - 1;
    if (b == -1 || a > b) return 0;
    ++a, ++b;
    if (a == 1)
      return sum(b);
    else
      return sum(b) - sum(a - 1);
  }
};
map<long long, fen*> mp;
struct ai {
  long long p = 0, r = 0, iq = 0;
} bots[100006];
bool cmp(pair<long long, pair<long long, long long> > x,
         pair<long long, pair<long long, long long> > y) {
  if (x.first == y.first) return x.second.first < y.second.first;
  return x.first < y.first;
}
void init(long long x) {
  p = bots[x].p;
  r = bots[x].r;
  iq = bots[x].iq;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> bots[i].p >> bots[i].r >> bots[i].iq;
  for (long long i = 0; i < n; i++) {
    init(i);
    A[co++] = pair<long long, pair<long long, long long> >(
        p, pair<long long, long long>(1, i));
    A[co++] = pair<long long, pair<long long, long long> >(
        p + r, pair<long long, long long>(2, i));
  }
  for (long long i = 0; i < n; i++) {
    init(i);
    if (mp.find(iq) == mp.end()) mp[iq] = new fen;
    mp[iq]->add_elem(p);
  }
  for (auto i : mp) {
    i.second->init();
  }
  sort(A, A + co, cmp);
  for (long long i = 0; i < co; i++) {
    long long sum = 0;
    p = A[i].first, iq = bots[A[i].second.second].iq,
    r = bots[A[i].second.second].r;
    long long type = A[i].second.first, ind = A[i].second.second;
    if (type == 0) {
    }
    if (type == 1) {
      for (long long i = max(0LL, iq - k); i < iq + k + 1; i++) {
        if (mp.find(i) == mp.end()) continue;
        sum += mp[i]->range_sum(p - r, p + r);
      }
      mp[iq]->update(p, 1);
    }
    if (type == 2) {
      mp[iq]->update(bots[A[i].second.second].p, -1);
    }
    ans += sum;
  }
  cout << ans << '\n';
}