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 n, k, ans, fw[100006];
vector<long long> v;
struct fen {
  vector<long long> v;
  vector<long long> fw;
  long long n = 0;
  fen() {
    v.clear();
    fw.clear();
    n = 0;
  }
  void add_elem(long long x) {
    v.push_back(x);
    n++;
  }
  void init() {
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    fw.clear();
    n = v.size();
    fw.resize(n + 2);
  }
  void update(long long x, long long nv) {
    x = lower_bound(v.begin(), v.end(), x) - v.begin();
    ++x;
    for (; x <= n; x += x & (-x)) fw[x] += nv;
  }
  long long sum(long long x) {
    if (x <= 0) return 0;
    long long res = 0;
    for (; x; x -= x & (-x)) res += fw[x];
    return res;
  }
  long long range_sum(long long a, long long b) {
    a = lower_bound(v.begin(), v.end(), a) - v.begin();
    b = upper_bound(v.begin(), v.end(), b) - v.begin() - 1;
    ++a, ++b;
    if (b == 0 || a > b || a > n || b > n) return 0;
    if (a == 1) return sum(b);
    return sum(b) - sum(a - 1);
  }
};
map<long long, fen*> mp;
struct arr {
  long long p, r, iq;
} A[100006];
bool cmp(arr a, arr b) { return a.r > b.r; }
int main() {
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> A[i].p >> A[i].r >> A[i].iq;
  sort(A, A + n, cmp);
  for (long long i = 0; i < n; i++) v.push_back(A[i].p);
  sort(v.begin(), v.end());
  for (long long i = 0; i < n; i++) {
    if (mp.find(A[i].iq) == mp.end()) mp[A[i].iq] = new fen;
    mp[A[i].iq]->add_elem(A[i].p);
  }
  for (auto i : mp) i.second->init();
  for (long long i = 0; i < n; i++) {
    long long pos = lower_bound(v.begin(), v.end(), A[i].p) - v.begin() + 1;
    long long lb = A[i].p - A[i].r;
    long long ub = A[i].p + A[i].r;
    if (lb <= ub) {
      for (long long j = max(0LL, A[i].iq - k); j < A[i].iq + k + 1; j++) {
        if (mp.find(j) == mp.end()) continue;
        ans += mp[j]->range_sum(lb, ub);
      }
    }
    mp[A[i].iq]->update(A[i].p, 1);
  }
  cout << ans << '\n';
}