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;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long N = 1e6 + 5;
const double eps = 1e-9;
long long mod = 1e9 + 7;
long long n, k;
struct node {
  long long x, r, L, R, q;
} p[N];
long long len;
long long b[N];
long long ans = 0;
long long sum[N];
inline void upd(long long x, long long d) {
  for (; x <= len; x += x & -x) sum[x] += d;
}
inline long long ask(long long x) {
  long long ret = 0;
  for (; x; x &= x - 1) ret += sum[x];
  return ret;
}
bool cmp1(node a, node b) { return a.r < b.r; }
bool cmp2(node a, node b) { return a.q < b.q; }
void cdq(long long l, long long r) {
  if (l == r) return;
  cdq(l, (l + ((r - l) >> 1))), cdq((l + ((r - l) >> 1)) + 1, r);
  long long p1, p2;
  p1 = p2 = (l + ((r - l) >> 1));
  for (long long i = l; i <= (l + ((r - l) >> 1)); i++) {
    while (p2 + 1 <= r && p[p2 + 1].q <= p[i].q + k) p2++, upd(p[p2].x, 1);
    while (p1 + 1 <= p2 && p[p1 + 1].q < p[i].q - k) p1++, upd(p[p1].x, -1);
    ans += ask(p[i].R) - ask(p[i].L - 1);
  }
  for (long long i = p1 + 1; i <= p2; i++) upd(p[i].x, -1);
  inplace_merge(p + l, p + (l + ((r - l) >> 1)) + 1, p + r + 1, cmp2);
}
signed main() {
  scanf("%lld", &n), scanf("%lld", &k);
  long long tim = 0;
  for (long long i = 1; i <= n; i++)
    scanf("%lld", &p[i].x), scanf("%lld", &p[i].r), scanf("%lld", &p[i].q),
        b[++tim] = p[i].x;
  sort(b + 1, b + 1 + tim);
  len = unique(b + 1, b + 1 + tim) - b - 1;
  for (long long i = 1; i <= n; i++) {
    p[i].L = lower_bound(b + 1, b + 1 + len, p[i].x - p[i].r) - b;
    p[i].R = upper_bound(b + 1, b + 1 + len, p[i].x + p[i].r) - b - 1;
    p[i].x = lower_bound(b + 1, b + 1 + len, p[i].x) - b;
  }
  sort(p + 1, p + 1 + n, cmp1);
  cdq(1, n);
  cout << ans;
}