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;
template <typename T>
ostream& operator<<(ostream& os, vector<T> a) {
  os << "( ";
  for (T& x : a) os << x << " ";
  os << ")\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> a) {
  os << "( ";
  for (T x : a) os << x << " ";
  os << ")\n";
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> a) {
  os << "(" << a.first << " " << a.second << ") ";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, complex<T> a) {
  os << "(r=" << a.real() << " i=" << a.imag() << ") ";
  return os;
}
const int base = 1000000007;
long long power(long long a, long long n, long long mod = base) {
  long long r = 1;
  while (n) {
    if (n & 1) r = r * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return r;
}
const int nmax = 100011;
int n, trie[nmax * 200][3], ntrie;
void push(int k, int key, int val) {
  for (int i = 30; i--;) {
    int t = (key >> i) & 1;
    if (trie[k][t] == 0) trie[k][t] = ++ntrie;
    k = trie[k][t];
    trie[k][2] += val;
  }
}
int query(int k, int key) {
  int ans = 0;
  for (int i = 30; i--;) {
    int t = (key >> i) & 1;
    if (t == 1) ans += trie[trie[k][0]][2];
    if (trie[k][t] == 0) break;
    k = trie[k][t];
  }
  return ans;
}
void update(int i, int p, int val) {
  for (++i; i <= n; i += i & -i) push(i, p, val);
}
int show(int i, int L, int H) {
  H = min(1000000000, H);
  L = max(L, 0);
  int ans = 0;
  for (++i; i; i -= i & -i) ans += query(i, H + 1) - query(i, L);
  return ans;
}
int main(int argc, char** argv) {
  int k;
  scanf("%d%d", &n, &k);
  vector<pair<int, pair<int, int>>> a(n);
  for (auto& A : a)
    scanf("%d%d%d", &A.first, &A.second.first, &A.second.second);
  sort(a.begin(), a.end());
  ntrie = n;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      heap;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    while (heap.size()) {
      auto tmp = heap.top();
      if (0)
        cout << "tmp"
             << " = " << tmp << endl;
      if (tmp.first >= a[i].first) break;
      int j = tmp.second;
      update(j, a[j].second.second, -1);
      heap.pop();
    }
    pair<int, pair<int, int>> tmp =
        make_pair(a[i].first - a[i].second.first, make_pair(-1, -1));
    int j = upper_bound(a.begin(), a.end(), tmp) - a.begin();
    if (0)
      cout << "tmp"
           << " = " << tmp << endl;
    if (0)
      cout << "j"
           << " = " << j << endl;
    ans += show(i, a[i].second.second - k, a[i].second.second + k) -
           show(j - 1, a[i].second.second - k, a[i].second.second + k);
    update(i, a[i].second.second, 1);
    heap.push({a[i].first + a[i].second.first, i});
  }
  cout << ans;
}