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.
#include <bits/stdc++.h>
using namespace std;
bool is_prime(long long n) {
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long getPow(long long a, long long b) {
  long long res = 1ll, tp = a;
  while (b) {
    if (b & 1ll) {
      res *= tp;
      res %= 1000000007;
    }
    tp *= tp;
    tp %= 1000000007;
    b >>= 1ll;
  }
  return res;
}
long long vec_mult(long long x1, long long y1, long long x2, long long y2,
                   long long x3, long long y3) {
  return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1));
}
void ok() {
  cout << "YES" << endl;
  exit(0);
}
void no() {
  cout << "NO" << endl;
  exit(0);
}
inline long long nxt() {
  long long x;
  cin >> x;
  return x;
}
struct Fenwick {
  int n;
  vector<int> a;
  Fenwick(int _n = 0) : n(_n), a(_n) {}
  void add(int pos, int x) {
    while (pos < n) {
      a[pos] += x;
      pos |= pos + 1;
    }
  }
  int get(int pos) {
    int res = 0;
    while (pos >= 0) {
      res += a[pos];
      pos = (pos & (pos + 1)) - 1;
    }
    return res;
  }
  int get(int l, int r) { return get(r) - get(l - 1); }
};
struct Robot {
  int x, r, iq;
  Robot() {}
  Robot(int t1, int t2, int t3) : x(t1), r(t2), iq(t3) {}
  bool operator<(const Robot& a) const { return r > a.r; }
};
const long long N = 2e5 + 5, inf = 1e18;
int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long n = nxt(), k = nxt();
  vector<Robot> mas(n);
  for (int i = 0; i < n; i++) {
    long long t1 = nxt(), t2 = nxt(), t3 = nxt();
    mas[i] = Robot(t1, t2, t3);
  }
  sort(mas.begin(), mas.end());
  vector<long long> iqs;
  for (int i = 0; i < n; i++) {
    iqs.push_back(mas[i].iq);
  }
  sort((iqs).begin(), (iqs).end());
  (iqs).resize(unique((iqs).begin(), (iqs).end()) - (iqs).begin());
  vector<vector<long long>> positions(iqs.size());
  for (int i = 0; i < n; i++) {
    int ind = lower_bound(iqs.begin(), iqs.end(), mas[i].iq) - iqs.begin();
    positions[ind].push_back(mas[i].x);
  }
  for (int i = 0; i < positions.size(); i++) {
    sort((positions[i]).begin(), (positions[i]).end());
    (positions[i])
        .resize(unique((positions[i]).begin(), (positions[i]).end()) -
                (positions[i]).begin());
  }
  vector<Fenwick> fenws;
  for (int i = 0; i < iqs.size(); i++) {
    fenws.push_back(Fenwick(positions[i].size()));
  }
  long long ans = 0;
  for (auto t : mas) {
    int l = lower_bound(iqs.begin(), iqs.end(), t.iq - k) - iqs.begin();
    while (l < iqs.size() && iqs[l] <= t.iq + k) {
      long long le =
          lower_bound(positions[l].begin(), positions[l].end(), t.x - t.r) -
          positions[l].begin();
      long long ri =
          upper_bound(positions[l].begin(), positions[l].end(), t.x + t.r) -
          positions[l].begin() - 1;
      ans += fenws[l].get(le, ri);
      l++;
    }
    int ind = lower_bound(iqs.begin(), iqs.end(), t.iq) - iqs.begin();
    int pos = lower_bound(positions[ind].begin(), positions[ind].end(), t.x) -
              positions[ind].begin();
    fenws[ind].add(pos, 1);
  }
  cout << ans;
  return 0;
}
