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;
int fastio() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin.tie(nullptr);
  return 0;
}
int __fastio = fastio();
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p);
template <typename A, typename B>
ostream &operator<<(ostream &os, const map<A, B> &m) {
  os << "{";
  string sep = "";
  for (auto e : m) os << sep << e.first << ": " << e.second, sep = ", ";
  return os << "}";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  string sep = "";
  for (auto e : v) os << sep << e, sep = ", ";
  return os << "]";
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
const int inf = 1000 << 20;
class Seg {
  int size;
  vector<long long> _data;

 public:
  Seg(int n) {
    size = 1;
    while (size < n) size *= 2;
    _data = vector<long long>(size * 2, 0);
  }
  long long ask(int left, int right) {
    long long ret = 0;
    for (left += size, right += size; left < right; left /= 2, right /= 2) {
      if (left & 1) {
        ret = ((ret) + (_data[left++]));
      }
      if (right & 1) {
        ret = ((ret) + (_data[--right]));
      }
    }
    return ret;
  }
  void insert(int x, long long val) {
    for (x += size; x > 0; x /= 2) {
      _data[x] = ((_data[x]) + (val));
    }
  }
};
class Bit {
  int size;
  vector<long long> _data;

 public:
  Bit(int n) {
    size = n + 2;
    _data = vector<long long>(size);
  }
  long long ask(int x) {
    long long ret = 0;
    for (++x; x; x &= x - 1) ret += _data[x];
    return ret;
  }
  void inc(int x, long long val) {
    for (++x; x < size; x += x & -x) _data[x] += val;
  }
};
template <typename K>
void assign(map<K, int> &mp) {
  int cnt = 0;
  for (auto &k : mp) {
    k.second = cnt++;
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  ;
  vector<int> X(n), R(n), Q(n);
  vector<pair<int, int>> xi(n);
  map<int, int> qmp;
  for (int i = 0; i < n; ++i) {
    cin >> X[i] >> R[i] >> Q[i];
    xi[i] = pair<int, int>(X[i], i);
    qmp[Q[i]];
  }
  sort(xi.begin(), xi.end());
  ;
  ;
  ;
  assign(qmp);
  vector<map<int, int>> mps((int((qmp).size())));
  for (int i = 0; i < n; ++i) {
    mps[qmp[Q[i]]][X[i]];
  }
  vector<Bit> bits;
  for (auto &mp : mps) {
    mp[inf * 2];
    assign(mp);
    bits.push_back(Bit((int((mp).size()))));
  };
  ;
  long long ans = 0;
  set<pair<int, int>> w;
  for (auto _i : xi) {
    int i = _i.second;
    while ((int((w).size())) && w.begin()->first < X[i]) {
      pair<int, int> p = *w.begin();
      w.erase(w.begin());
      int j = p.second;
      int xq = mps[qmp[Q[j]]][X[j]];
      bits[qmp[Q[j]]].inc(xq, -1);
    }
    int left = X[i] - R[i];
    int right = X[i] + R[i] + 1;
    ;
    for (int q = Q[i] - k; q <= Q[i] + k; ++q) {
      if (qmp.find(q) != qmp.end()) {
        int leftQ = mps[qmp[q]].lower_bound(left)->second;
        int rightQ = mps[qmp[q]].lower_bound(right)->second;
        ;
        ;
        long long val =
            bits[qmp[q]].ask(rightQ - 1) - bits[qmp[q]].ask(leftQ - 1);
        ;
        ans += val;
      }
    }
    int xq = mps[qmp[Q[i]]][X[i]];
    ;
    bits[qmp[Q[i]]].inc(xq, 1);
    w.insert(pair<int, int>(X[i] + R[i], i));
  }
  cout << ans << "\n";
}