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 _ = 3e5 + 5;
inline int read() {
  char ch = '!';
  int z = 1, num = 0;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') z = -1, ch = getchar();
  while (ch <= '9' && ch >= '0')
    num = (num << 3) + (num << 1) + ch - '0', ch = getchar();
  return z * num;
}
int n, K, a[_];
struct ha {
  int x, r, q;
  bool operator<(const ha &A) const { return x < A.x; }
} t[_];
long long ans;
map<int, int> c[_];
struct Ha {
  int x, id;
  bool operator<(const Ha &A) const { return x > A.x; }
};
priority_queue<Ha> Q;
map<int, int>::iterator P;
void insert(int x, int op) {
  while (x <= a[0]) {
    c[x][op]++;
    x += (x & (-x));
  }
}
void del(int x, int op) {
  while (x <= a[0]) {
    c[x][op]--;
    x += (x & (-x));
  }
}
int qy(int x, int l, int r) {
  int s = 0;
  l = max(l, 0);
  while (x) {
    for (P = c[x].lower_bound(l); P != c[x].end() && P->first <= r; ++P)
      s += P->second;
    x -= (x & (-x));
  }
  return s;
}
int find(int x) {
  int k = lower_bound(a + 1, a + 1 + a[0], x) - a;
  return k;
}
int main() {
  n = read(), K = read();
  for (int i = 1; i <= n; ++i) {
    t[i].x = read(), t[i].r = read(), t[i].q = read();
    a[++a[0]] = t[i].x - t[i].r;
    a[++a[0]] = t[i].x + t[i].r;
    a[++a[0]] = t[i].x;
  }
  sort(t + 1, t + 1 + n);
  sort(a + 1, a + 1 + a[0]);
  a[0] = unique(a + 1, a + 1 + a[0]) - a - 1;
  for (int i = 1; i <= n; ++i) {
    while (!Q.empty() && Q.top().x < t[i].x)
      del(find(t[Q.top().id].x), t[Q.top().id].q), Q.pop();
    int l = find(t[i].x - t[i].r), r = find(t[i].x + t[i].r);
    ans += qy(r, t[i].q - K, t[i].q + K) - qy(l - 1, t[i].q - K, t[i].q + K);
    Q.push((Ha){t[i].x + t[i].r, i});
    insert(find(t[i].x), t[i].q);
  }
  printf("%lld\n", ans);
  return 0;
}