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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int desll[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const int mod = 998244353;
const int maxn = 1e6 + 7;
const int maxm = 1e6 + 1;
const double eps = 1e-8;
int n, k, m;
int ar[maxn];
long long sum[maxn], ans = 0, len;
map<long long, int> ma;
struct node {
  long long L, R, r, x, q;
} no[maxn];
bool cmp1(node n1, node n2) { return n1.r < n2.r; }
bool cmp2(node n1, node n2) { return n1.q < n2.q; }
void add(int x, int val) {
  while (x <= len) {
    sum[x] += val;
    x += x & (-x);
  }
}
long long que(int x) {
  long long ans = 0;
  while (x > 0) {
    ans += sum[x];
    x -= x & (-x);
  }
  return ans;
}
void dcp(int a, int b) {
  if (a == b) return;
  int mid = (a + b) >> 1;
  dcp(a, mid);
  dcp(mid + 1, b);
  int p1, p2;
  p1 = p2 = mid + 1;
  for (int i = a; i <= mid; i++) {
    while (p2 <= b && no[p2].q <= no[i].q + m) {
      add(no[p2].x, 1);
      p2++;
    }
    while (p1 < p2 && no[p1].q < no[i].q - m) {
      add(no[p1].x, -1);
      p1++;
    }
    ans += que(no[i].R) - que(no[i].L - 1);
  }
  for (int i = p1; i < p2; i++) {
    add(no[i].x, -1);
  }
  inplace_merge(no + a, no + mid + 1, no + b + 1, cmp2);
}
int main() {
  memset(sum, 0, sizeof(sum));
  scanf("%d%d", &n, &m);
  len = 0;
  for (int i = 1; i <= n; i++) {
    long long a, b, c;
    scanf("%lld%lld%lld", &a, &b, &c);
    no[i].x = a;
    no[i].r = b;
    no[i].q = c;
    no[i].L = a - b;
    no[i].R = a + b;
    ar[++len] = a;
    ar[++len] = a + b;
    ar[++len] = a - b;
  }
  sort(ar + 1, ar + 1 + len);
  len = unique(ar + 1, ar + len + 1) - ar - 1;
  for (int i = 1; i <= len; i++) {
    ma[ar[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    no[i].L = ma[no[i].L];
    no[i].R = ma[no[i].R];
    no[i].x = ma[no[i].x];
  }
  sort(no + 1, no + 1 + n, cmp1);
  dcp(1, n);
  printf("%I64d\n", ans);
  return 0;
}