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;
struct BIT {
  vector<int> bit;
  int sz;
  BIT() {
    bit.clear();
    sz = 0;
  }
  BIT(int n) {
    sz = n;
    bit.assign(n + 1, 0);
  }
  void update(int pos, int v) {
    for (; pos <= sz; pos += pos & (-pos)) bit[pos] += v;
  }
  int sum(int pos) {
    int ans = 0;
    for (; pos; pos -= pos & (-pos)) ans += bit[pos];
    return ans;
  }
};
struct wavelet {
  int low, high;
  vector<int> b;
  BIT bit;
  wavelet *left, *right;
  wavelet(int *from, int *to, int l, int r) {
    low = l, high = r;
    left = NULL, right = NULL;
    bit = BIT(to - from + 1);
    if (l == r || from == to) return;
    int mid = (l + r) >> 1;
    auto f = [mid](int a) { return a <= mid; };
    b.push_back(0);
    for (int *it = from; it != to; it++) {
      b.push_back(b.back() + f(*it));
    }
    int *pivo = stable_partition(from, to, f);
    left = new wavelet(from, pivo, l, mid);
    right = new wavelet(pivo, to, mid + 1, r);
  }
  int count_active(int l, int r) { return bit.sum(r) - bit.sum(l - 1); }
  void toggle(int pos, int v) {
    bit.update(pos, v);
    if (low == high) return;
    int rb = b[pos];
    int lb = b[pos - 1];
    if (rb != lb) {
      left->toggle(lb + 1, v);
    } else
      right->toggle(pos - rb, v);
  }
  int query(int l, int r, int x, int y) {
    if (high < x || low > y || l > r) return 0;
    if (x <= low && y >= high) return count_active(l, r);
    int rb = b[r];
    int lb = b[l - 1];
    int ans = 0;
    if (left) ans += left->query(lb + 1, rb, x, y);
    if (right) ans += right->query(l - lb, r - rb, x, y);
    return ans;
  }
};
struct person {
  int x, r, q;
} input[101010];
int n, k, vet[101010];
set<pair<int, pair<int, int> > > s;
wavelet *root;
int get_l(int pos, int x) {
  int ans = 0;
  for (int j = 20; j >= 0; j--) {
    if (ans + (1 << j) >= pos) continue;
    if (input[ans + (1 << j)].x < x) {
      ans += (1 << j);
    }
  }
  return ans + 1;
}
void add(pair<int, int> foo) { root->toggle(foo.first, 1); }
void remove(pair<int, int> foo) { root->toggle(foo.first, -1); }
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", &input[i].x, &input[i].r, &input[i].q);
  }
  sort(input + 1, input + n + 1, [](person a, person b) { return a.x < b.x; });
  for (int i = 1; i <= n; i++) {
    vet[i] = input[i].q;
  }
  root = new wavelet(vet + 1, vet + n + 1, 0, 1e9);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    while (s.size() && s.begin()->first < input[i].x) {
      remove(s.begin()->second);
      s.erase(s.begin());
    }
    int l = get_l(i, input[i].x - input[i].r);
    ans += root->query(l, i, input[i].q - k, input[i].q + k);
    add(pair<int, int>(i, input[i].q));
    s.insert(pair<int, pair<int, int> >(input[i].x + input[i].r,
                                        pair<int, int>(i, input[i].q)));
  }
  printf("%lld\n", ans);
}