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;
template <typename Value>
class Fenwick {
 public:
  Fenwick(int N) : size(N), container(N, 0) {}
  Fenwick(const vector<Value>& initial_values)
      : Fenwick(initial_values.size()) {
    for (int p = 0; p < size; p++) {
      int q = p | (p + 1);
      container[p] += initial_values[p];
      if (q < size) container[q] += container[p];
    }
  }
  void Add(int p, Value x) {
    for (; p < size; p |= (p + 1)) container[p] += x;
  }
  Value GetRange(int l, int r) {
    if (l > 0) return GetRange(0, r) - GetRange(0, l - 1);
    Value res = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) res += container[r];
    return res;
  }
  Value Get(int p) { return GetRange(p, p); }
  void Set(int p, Value x) { Add(p, x - Get(p)); }
  void Debug() {
    cout << "Internal container representation (size = " << size << "):\n";
    for (int i = 0; i < size; i++) cout << container[i] << " ";
    cout << "\nValues of the entries:\n";
    for (int i = 0; i < size; i++) cout << Get(i) << " ";
    cout << "\n";
    cout.flush();
  }

 private:
  int size;
  vector<Value> container;
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> x(N), r(N), q(N);
  for (int i = 0; i < N; i++) cin >> x[i] >> r[i] >> q[i];
  set<int> coord;
  for (int i = 0; i < N; i++) coord.insert(x[i]);
  vector<int> coord_vec(coord.begin(), coord.end());
  int C = coord_vec.size();
  vector<int> xx(N), le(N), ri(N);
  for (int i = 0; i < N; i++) {
    xx[i] = lower_bound(coord_vec.begin(), coord_vec.end(), x[i]) -
            coord_vec.begin();
    le[i] = lower_bound(coord_vec.begin(), coord_vec.end(), x[i] - r[i]) -
            coord_vec.begin();
    ri[i] = (upper_bound(coord_vec.begin(), coord_vec.end(), x[i] + r[i]) -
             coord_vec.begin()) -
            1;
  }
  vector<int> o(N);
  for (int i = 0; i < N; i++) o[i] = i;
  sort(o.begin(), o.end(), [&](int i, int j) { return q[i] < q[j]; });
  int aq = -1;
  long long res = 0;
  Fenwick<int> ff(C);
  for (int i = 0; i < N; i++) {
    if (aq == q[o[i]]) continue;
    aq = q[o[i]];
    vector<int> b;
    int k = i;
    while (k < N and q[o[k]] <= aq + K) b.push_back(o[k]), k++;
    k = i - 1;
    while (k >= 0 and q[o[k]] >= aq - K) b.push_back(o[k]), k--;
    sort(b.begin(), b.end(), [&](int i, int j) {
      if (r[i] == r[j]) return q[i] < q[j];
      return r[i] > r[j];
    });
    for (int a : b) {
      if (q[a] == aq) {
        res += ff.GetRange(le[a], ri[a]);
      }
      ff.Add(xx[a], 1);
    }
    for (int a : b) {
      ff.Add(xx[a], -1);
    }
  }
  cout << res << "\n";
}