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;
int n, k, m;
long long ans;
int pos1[100005], pos2[100005];
struct node {
  int x, y, z, L, R;
  int id, flag;
} p[100005];
bool cmp1(node a, node b) {
  if (a.y != b.y) return a.y > b.y;
  if (a.z != b.z) return a.z < b.z;
  return a.x < b.x;
}
bool cmp2(node a, node b) {
  if (a.z != b.z) return a.z < b.z;
  if (a.x != b.x) return a.x < b.x;
  return a.y > b.y;
}
int c[3 * 100005];
void add(int x, int v) {
  for (; x <= m; x += x & -x) c[x] += v;
}
int ask(int x) {
  int sum = 0;
  for (; x; x -= x & -x) sum += c[x];
  return sum;
}
void clear(int x) {
  for (; x <= m; x += x & -x) {
    if (!c[x]) return;
    c[x] = 0;
  }
}
void solve(int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  solve(l, mid), solve(mid + 1, r);
  sort(p + l, p + mid + 1, cmp2);
  sort(p + mid + 1, p + r + 1, cmp2);
  int j1 = l, j2 = l - 1;
  for (int i = mid + 1; i <= r; i++) {
    while (j1 <= mid && p[i].z - p[j1].z > k) add(p[j1].x, -1), j1++;
    while (j2 < mid && p[j2 + 1].z - p[i].z <= k) {
      j2++;
      add(p[j2].x, 1);
    }
    ans += ask(p[i].R) - ask(p[i].L - 1);
  }
  for (int i = j1; i <= j2; i++) add(p[i].x, -1);
}
int b[3 * 100005], cnt;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    int a, r, c;
    scanf("%d%d%d", &a, &r, &c);
    p[i].x = a;
    p[i].y = r;
    p[i].z = c;
    p[i].L = max(0, a - r);
    p[i].R = a + r;
    b[++cnt] = p[i].x;
    b[++cnt] = p[i].L;
    b[++cnt] = p[i].R;
  }
  sort(b + 1, b + cnt + 1);
  m = unique(b + 1, b + cnt + 1) - b - 1;
  for (int i = 1; i <= n; i++) {
    p[i].x = lower_bound(b + 1, b + m + 1, p[i].x) - b;
    p[i].L = lower_bound(b + 1, b + m + 1, p[i].L) - b;
    p[i].R = lower_bound(b + 1, b + m + 1, p[i].R) - b;
  }
  sort(p + 1, p + n + 1, cmp1);
  solve(1, n);
  printf("%lld\n", ans);
  return 0;
}