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;
uint64_t rnd_data = 0xDEADBEEFDULL;
inline void my_srand(int seed) { rnd_data = ((uint64_t)seed << 16) | 0x330E; }
inline int my_rand() {
  rnd_data = rnd_data * 0x5DEECE66DULL + 0xB;
  return (rnd_data >> 17) & 0x7FFFFFFF;
}
template <typename T>
void my_random_shuffle(T b, T e) {
  for (int i = (1); i <= (int)((int)(e - b) - 1); i++) {
    swap(b[i], b[my_rand() % (i + 1)]);
  }
}
template <class _T>
inline _T sqr(const _T &x) {
  return x * x;
}
template <typename type_t, typename less_t = std::less<type_t>>
inline bool uin(type_t &a, const type_t &b, const less_t &ls = less_t()) {
  return ls(b, a) ? a = b, true : false;
}
template <typename type_t, typename less_t = std::less<type_t>>
inline bool uax(type_t &a, const type_t &b, const less_t &ls = less_t()) {
  return ls(a, b) ? a = b, true : false;
}
const long double PI = 3.1415926535897932384626433832795L;
const long double EPS = 1e-9;
struct tr {
  int x, r, s;
};
bool operator<(const tr &l, const tr &r) { return l.r > r.r; }
int n, k;
tr a[102400];
int z;
int xs[102400];
int xx;
map<int, int> t[1 << 18];
void tadd(int x, int s, int val) {
  x = lower_bound(xs, xs + xx, x) - xs;
  x += z;
  while (x) {
    t[x][s] += val;
    x >>= 1;
  }
}
int tsum(int l, int r, int s) {
  l = lower_bound(xs, xs + xx, l) - xs;
  r = upper_bound(xs, xs + xx, r) - xs - 1;
  int ans = 0;
  l += z;
  r += z;
  while (l <= r) {
    if (l & 1) {
      for (auto it = t[l].lower_bound(s - k);
           it != t[l].end() && it->first <= s + k; ++it) {
        ans += it->second;
      }
    }
    if (!(r & 1)) {
      for (auto it = t[r].lower_bound(s - k);
           it != t[r].end() && it->first <= s + k; ++it) {
        ans += it->second;
      }
    }
    l = (l + 1) >> 1;
    r = (r - 1) >> 1;
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < (int)(n); i++) {
    scanf("%d%d%d", &a[i].x, &a[i].r, &a[i].s);
  }
  for (int i = 0; i < (int)(n); i++) {
    xs[i] = a[i].x;
  }
  sort(xs, xs + n);
  xx = unique(xs, xs + n) - xs;
  z = 1;
  while (z < n) z <<= 1;
  sort(a, a + n);
  long long ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    ans += tsum(a[i].x - a[i].r, a[i].x + a[i].r, a[i].s);
    tadd(a[i].x, a[i].s, 1);
  }
  cout << ans << endl;
  return 0;
}