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 maxn = 1e6 + 5;
struct pos {
  long long int x, r, q;
};
unordered_map<long long int, pair<long long, long long> > m1;
pos Pos[maxn];
vector<long long> v1;
bool compare(const pos& a, const pos& b) { return a.r > b.r; }
struct node {
  node* left;
  node* right;
  long long int val;
  long long int from, to;
  node() {
    val = 0;
    from = 0;
    to = maxn - 1;
    left = NULL;
    right = NULL;
  }
  void extend() {
    if (left == NULL) {
      left = new node();
      left->from = from;
      left->to = from + (to - from) / 2;
      left->val = 0;
    }
    if (right == NULL) {
      right = new node();
      right->from = from + (to - from) / 2 + 1;
      right->to = to;
      right->val = 0;
    }
  }
};
node* st[maxn];
long long int get(node* cur, int left, int right) {
  if (cur == NULL) return 0;
  if ((cur->from) > right or (cur->to) < left) return 0;
  if (cur->from >= left and cur->to <= right) {
    return cur->val;
  }
  long long int ans1 = get(cur->left, left, right);
  long long int ans2 = get(cur->right, left, right);
  return ans1 + ans2;
}
void update(node* cur, int ind, int val) {
  if ((cur->from) > ind or (cur->to) < ind) return;
  if (cur->from == cur->to) {
    cur->val += val;
    return;
  }
  cur->extend();
  update(cur->left, ind, val);
  update(cur->right, ind, val);
  cur->val = cur->left->val + cur->right->val;
}
void solve() {
  int n, k;
  scanf("%d", &n);
  scanf("%d", &k);
  int ind = 0;
  for (int i = 0; i <= n - 1; i++) {
    long long int X, R, Q;
    scanf("%lld", &X);
    scanf("%lld", &R);
    scanf("%lld", &Q);
    Pos[i].x = X;
    Pos[i].r = R;
    Pos[i].q = Q;
    if (m1.find(Q) == m1.end()) {
      m1[Q].first = ind++;
      m1[Q].second = 1;
    } else {
      m1[Q].second++;
    }
    v1.push_back(X);
    v1.push_back(X + R);
    v1.push_back(X - R);
  }
  sort((v1).begin(), (v1).end());
  v1.resize(unique((v1).begin(), (v1).end()) - v1.begin());
  sort(Pos, Pos + n, compare);
  for (auto it = m1.begin(); it != m1.end(); ++it) {
    int val = it->second.first;
    st[val] = new node;
  }
  long long int ans = 0;
  for (int i = 0; i <= n - 1; i++) {
    long long int IQ = Pos[i].q;
    long long int low = IQ - k;
    long long int high = IQ + k;
    for (int j = low; j <= high; j++) {
      if (m1.find(j) != m1.end()) {
        int val = m1[j].first;
        long long int lower =
            lower_bound((v1).begin(), (v1).end(), Pos[i].x - Pos[i].r) -
            v1.begin();
        long long int upper =
            lower_bound((v1).begin(), (v1).end(), Pos[i].x + Pos[i].r) -
            v1.begin();
        ans += get(st[val], lower, upper);
      }
    }
    long long int val = m1[IQ].first;
    long long int ind =
        lower_bound((v1).begin(), (v1).end(), Pos[i].x) - v1.begin();
    update(st[val], ind, 1);
  }
  printf("%lld\n", ans);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}