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;
struct IdGen {
  unordered_map<int, int> mp;
  vector<int> lazy;
  void insert(int x) {
    assert(mp.empty());
    lazy.push_back(x);
  }
  void process() {
    assert(mp.empty());
    mp.reserve((int)1e5);
    mp.max_load_factor(0.25);
    sort(lazy.begin(), lazy.end());
    lazy.erase(unique(lazy.begin(), lazy.end()), lazy.end());
    for (int i = 0; i < (int)lazy.size(); ++i) mp[lazy[i]] = i;
    lazy.clear();
  }
  int getId(int x) const {
    assert(lazy.empty());
    return mp.at(x);
  }
  int size() const {
    assert(lazy.empty());
    return mp.size();
  }
};
int ftv[(int)1e5 + 2];
struct FT {
  int v_size;
  vector<int> dirty;
  FT(int n) { v_size = n + 1; }
  void reset(int i) {
    for (++i; i < v_size; i += i & -i) ftv[i] = 0;
  }
  void update(int i, const int a) {
    dirty.push_back(i);
    for (++i; i < v_size; i += i & -i) ftv[i] += a;
  }
  int query(int i) const {
    assert(i >= -1 && i < v_size - 1);
    int sum = 0;
    for (++i; i; i -= i & -i) sum += ftv[i];
    return sum;
  }
  int query(int i, int j) const { return query(j) - query(i - 1); }
  ~FT() {
    for (auto &&x : dirty) reset(x);
  }
};
int N;
int x[(int)1e5];
int r[(int)1e5];
int lft[(int)1e5];
int rght[(int)1e5];
int curr[(int)1e5];
inline long long f(const vector<int> &v) {
  long long res = 0;
  FT ft(N);
  for (auto &&x : v) {
    res += ft.query(lft[x], rght[x]);
    ft.update(curr[x], 1);
  }
  return res;
}
bool lessRobot(const int i, const int j) { return r[i] > r[j]; };
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int K;
  cin >> N >> K;
  map<int, vector<int>> mp;
  IdGen idGen;
  set<int> xSet;
  for (int i = 0; i < N; ++i) {
    int q;
    cin >> x[i] >> r[i] >> q;
    mp[q].emplace_back(i);
    idGen.insert(x[i]);
    xSet.insert(x[i]);
  }
  idGen.process();
  cerr << "state 1\n";
  for (int i = 0; i < N; ++i) {
    lft[i] = idGen.getId(*(xSet.lower_bound(x[i] - r[i])));
    rght[i] = idGen.getId(*prev(xSet.upper_bound(x[i] + r[i])));
    curr[i] = idGen.getId(x[i]);
  }
  cerr << "state 2\n";
  for (auto &&x : mp) sort(x.second.begin(), x.second.end(), lessRobot);
  cerr << "state 3\n";
  long long ans = 0;
  unordered_map<int, long long> sameIqCnt;
  sameIqCnt.reserve((int)2e5);
  sameIqCnt.max_load_factor(0.25);
  cerr << "state 3.1\n";
  for (auto &&x : mp) ans += (sameIqCnt[x.first] = f(x.second));
  cerr << "state 3.2\n";
  vector<pair<int, vector<int>>> v(mp.begin(), mp.end());
  cerr << "state 4\n";
  for (int diff = 1; diff <= K; ++diff) {
    for (auto it1 = v.begin(), it2 = v.begin(); it1 != v.end(); ++it1) {
      while (it2 != v.end() && it2->first < it1->first + diff) ++it2;
      if (it2 == v.end() || it2->first != it1->first + diff) continue;
      vector<int> u(it1->second.size() + it2->second.size());
      merge(it1->second.begin(), it1->second.end(), it2->second.begin(),
            it2->second.end(), u.begin(), lessRobot);
      ans += f(u) - sameIqCnt.at(it1->first) - sameIqCnt.at(it2->first);
    }
  }
  cout << ans << '\n';
  return 0;
}