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 N = 100010;
struct node {
  int x, r, s;
  bool operator<(const node &_) const { return r > _.r; }
} A[N];
int B[N];
struct Binary_Indexed_Tree {
  vector<int> num, sum;
  int n;
  void init(int x) { num.push_back(x); }
  void build() {
    num.push_back(-1);
    sort(num.begin(), num.end());
    n = unique(num.begin(), num.end()) - num.begin() - 1;
    sum.resize(n + 1);
  }
  void Add(int x) {
    int i = upper_bound(num.begin(), num.begin() + n + 1, x) - num.begin() - 1;
    while (i <= n) {
      sum[i]++;
      i += i & -i;
    }
  }
  int Query(int x, int t = 0) {
    int i;
    if (t == 0) {
      i = upper_bound(num.begin(), num.begin() + n + 1, x) - num.begin() - 1;
    } else {
      i = lower_bound(num.begin(), num.begin() + n + 1, x) - num.begin() - 1;
    }
    int res = 0;
    while (i > 0) {
      res += sum[i];
      i -= i & -i;
    }
    return res;
  }
} BIT[N];
int main() {
  int n, K, i, j;
  scanf("%d%d", &n, &K);
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d", &A[i].x, &A[i].r, &A[i].s);
    B[i] = A[i].s;
  }
  sort(A + 1, A + 1 + n);
  sort(B + 1, B + 1 + n);
  int h = unique(B + 1, B + 1 + n) - B - 1;
  for (i = 1; i <= n; i++) {
    A[i].s = lower_bound(B + 1, B + 1 + h, A[i].s) - B;
    BIT[A[i].s].init(A[i].x);
  }
  for (i = 1; i <= h; i++) {
    BIT[i].build();
  }
  long long Ans = 0;
  for (i = 1; i <= n; i++) {
    for (j = A[i].s; j >= 1 && B[j] >= B[A[i].s] - K; j--) {
      Ans += BIT[j].Query(A[i].x + A[i].r) - BIT[j].Query(A[i].x - A[i].r, 1);
    }
    for (j = A[i].s + 1; j <= h && B[j] <= B[A[i].s] + K; j++) {
      Ans += BIT[j].Query(A[i].x + A[i].r) - BIT[j].Query(A[i].x - A[i].r, 1);
    }
    BIT[A[i].s].Add(A[i].x);
  }
  printf("%lld\n", Ans);
  return 0;
}