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;
void make_uni(vector<int> &v) {
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
}
int get(vector<int> &v, int d) {
  return lower_bound(v.begin(), v.end(), d) - v.begin();
}
int getu(vector<int> &v, int d) {
  return upper_bound(v.begin(), v.end(), d) - v.begin();
}
int n, k;
vector<tuple<int, int, int> > que;
int main() {
  scanf("%d %d", &n, &k);
  vector<int> c1;
  for (int i = 0, a, b, c; i < n; ++i) {
    scanf("%d %d %d", &a, &b, &c);
    c1.emplace_back(c);
    que.emplace_back(a, b, c);
  }
  make_uni(c1);
  vector<vector<int> > c2(c1.size());
  for (int i = 0, a, b, c; i < n; ++i) {
    tie(a, b, c) = que[i];
    c2[get(c1, c)].emplace_back(a + b);
  }
  for (int i = 0; i < c2.size(); ++i) make_uni(c2[i]);
  vector<vector<vector<int> > > c3(c2.size());
  for (int i = 0; i < c3.size(); ++i) c3[i].resize(c2[i].size());
  for (int i = 0, a, b, c; i < n; ++i) {
    tie(a, b, c) = que[i];
    int k1 = get(c1, c);
    int k2 = get(c2[k1], a + b);
    for (int i = k2 + 1; i; i -= i & -i) c3[k1][i - 1].emplace_back(a);
  }
  for (int i = 0; i < c3.size(); ++i)
    for (int j = 0; j < c3[i].size(); ++j) make_uni(c3[i][j]);
  vector<vector<vector<int> > > t(c3.size());
  for (int i = 0; i < c3.size(); ++i) {
    t[i].resize(c3[i].size());
    for (int j = 0; j < t[i].size(); ++j) t[i][j].resize(c3[i][j].size());
  }
  sort(que.begin(), que.end(),
       [&](const tuple<int, int, int> &a, const tuple<int, int, int> &b) {
         return get<0>(a) < get<0>(b);
       });
  long long sum = 0;
  for (auto &x : que) {
    int a, b, c;
    tie(a, b, c) = x;
    for (int l = get(c1, c - k), r = getu(c1, c + k); l != r; ++l)
      for (int i = get(c2[l], a) + 1; i <= c2[l].size(); i += i & -i)
        for (int j = get(c3[l][i - 1], a - b) + 1; j <= c3[l][i - 1].size();
             j += j & -j)
          sum += t[l][i - 1][j - 1];
    int p = get(c1, c);
    for (int i = get(c2[p], a + b) + 1; i; i -= i & -i)
      for (int j = get(c3[p][i - 1], a) + 1; j; j -= j & -j)
        t[p][i - 1][j - 1]++;
  }
  printf("%lld\n", sum);
}