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 N, K, x[100010], r[100010], q[100010], pret[100010], sled[100010], hshidx;
long long bit[5 * 100010], rez;
vector<int> iq[100010];
vector<pair<int, int> > tr;
set<int> sQ, sX;
map<int, int> hQ, rhQ, hX;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
priority_queue<pair<int, int> > pq1;
bool cmp(pair<int, int> a, pair<int, int> b) { return x[a.first] < x[b.first]; }
void update(int x, int val) {
  for (; x < 5 * 100010; x += x & -x) bit[x] += val;
}
long long query(int l, int r) {
  long long sum = 0;
  for (; r > 0; r -= r & -r) sum += bit[r];
  for (l--; l > 0; l -= l & -l) sum -= bit[l];
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  for (int i = 1; i <= N; i++) {
    cin >> x[i] >> r[i] >> q[i];
    sX.insert(x[i]);
    sX.insert(x[i] + r[i]);
    sX.insert(x[i] - r[i]);
    sQ.insert(q[i]);
  }
  hshidx = 0;
  for (auto x : sX) hX[x] = ++hshidx;
  hshidx = 0;
  for (auto q : sQ) hQ[q] = ++hshidx, rhQ[hshidx] = q;
  for (int i = 1; i <= N; i++) {
    iq[hQ[q[i]]].push_back(i);
    pret[i] = hX[x[i] - r[i]];
    sled[i] = hX[x[i] + r[i]];
    x[i] = hX[x[i]];
  }
  for (int i = 1; i <= int((sQ).size()); i++) {
    for (int j = i; j <= int((sQ).size()) && rhQ[j] <= rhQ[i] + K; j++) {
      for (auto x : iq[j]) tr.push_back({x, (i == j)});
    }
    sort(begin(tr), end(tr), cmp);
    for (auto cur : tr) {
      int idx = cur.first;
      if (cur.second) {
        while (!pq.empty() && pq.top().first < x[idx])
          update(pq.top().second, -1), pq.pop();
        rez += query(pret[idx], x[idx]);
      }
      update(x[idx], 1);
      pq.push({sled[idx], x[idx]});
    }
    while (!pq.empty()) update(pq.top().second, -1), pq.pop();
    for (int k = int((tr).size()) - 1; k >= 0; k--) {
      pair<int, int> cur = tr[k];
      int idx = cur.first;
      if (cur.second) {
        while (!pq1.empty() && pq1.top().first > x[idx])
          update(pq1.top().second, -1), pq1.pop();
        rez += query(x[idx], sled[idx]);
      } else {
        update(x[idx], 1);
        pq1.push({pret[idx], x[idx]});
      }
    }
    while (!pq1.empty()) update(pq1.top().second, -1), pq1.pop();
    tr.clear();
  }
  cout << rez;
  return 0;
}