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 mod = 1000000007;
long long large = 2000000000000000000LL;
vector<long long> sum;
int up;
long long uv;
void update(int o, int l, int r) {
  if (l == r) {
    sum[o] += uv;
  } else {
    int m = (l + r) / 2;
    if (up <= m) update(o * 2, l, m);
    if (up > m) update(o * 2 + 1, m + 1, r);
    sum[o] = sum[o * 2] + sum[o * 2 + 1];
  }
}
int ql, qr;
long long re;
void query(int o, int l, int r) {
  if (qr < ql) return;
  if (ql <= l && qr >= r) {
    re += sum[o];
  } else {
    int m = (l + r) / 2;
    if (ql <= m) query(o * 2, l, m);
    if (qr > m) query(o * 2 + 1, m + 1, r);
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n, 0), r = x, q = x;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &x[i], &r[i], &q[i]);
  }
  vector<int> uni;
  for (int i = 0; i < n; i++) uni.push_back(q[i]);
  sort(uni.begin(), uni.end());
  uni.erase(unique(uni.begin(), uni.end()), uni.end());
  int sz = (int)uni.size();
  map<int, int> comp;
  for (int i = 0; i < sz; i++) comp[uni[i]] = i;
  vector<vector<int> > adj(sz, vector<int>());
  for (int i = 0; i < n; i++) adj[comp[q[i]]].push_back(i);
  long long ans = 0;
  for (int i = 0; i < sz; i++) {
    int Q = uni[i];
    int y = upper_bound(uni.begin(), uni.end(), uni[i] - k - 1) - uni.begin();
    vector<int> uni(1, -1000000010);
    vector<pair<pair<int, int>, int> > eve;
    for (int j = y; j <= i; j++) {
      for (int k = 0; k < (int)adj[j].size(); k++) {
        int id = adj[j][k];
        eve.push_back(
            pair<pair<int, int>, int>(pair<int, int>(x[id] - r[id], 1), id));
        eve.push_back(pair<pair<int, int>, int>(
            pair<int, int>(x[id] + r[id] + 1, 0), id));
        uni.push_back(x[id]);
      }
    }
    for (int j = 0; j < (int)adj[i].size(); j++) {
      int id = adj[i][j];
      eve.push_back(pair<pair<int, int>, int>(pair<int, int>(x[id], 2), id));
    }
    sort(eve.begin(), eve.end());
    uni.push_back(2000000010);
    sort(uni.begin(), uni.end());
    uni.erase(unique(uni.begin(), uni.end()), uni.end());
    map<int, int> comp;
    for (int j = 0; j < (int)uni.size(); j++) comp[uni[j]] = j;
    int sz = (int)uni.size();
    sum.assign(4 * sz + 10, 0);
    long long temp = 0;
    for (int j = 0; j < (int)eve.size(); j++) {
      int ty = eve[j].first.second;
      int id = eve[j].second;
      if (ty == 1) {
        up = comp[x[id]];
        uv = 1;
        if (q[id] == Q) uv = 1000000000;
        update(1, 0, sz - 1);
      }
      if (ty == 0) {
        up = comp[x[id]];
        uv = -1;
        if (q[id] == Q) uv = -1000000000;
        update(1, 0, sz - 1);
      }
      if (ty == 2) {
        ql = upper_bound(uni.begin(), uni.end(), x[id] - r[id] - 1) -
             uni.begin();
        qr = upper_bound(uni.begin(), uni.end(), x[id] + r[id]) - uni.begin();
        qr--;
        re = 0;
        query(1, 0, sz - 1);
        ans += re % 1000000000LL;
        temp += re / 1000000000LL;
      }
    }
    temp -= (long long)adj[i].size();
    temp /= 2;
    ans += temp;
  }
  cout << ans << endl;
  return 0;
}