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;
map<int, int> m;
vector<int> zb, b;
pair<int, pair<int, int>> a[100007];
int lk[100007], rk[100007], seg[2][12 * 100007], iq[100007], rg[100007],
    x[100007];
bool cmp(int p, int q) { return rg[p] > rg[q]; }
void upd(int k, int l, int r, int v, int t, int ind) {
  if (l == r) {
    seg[k][ind] += v;
    return;
  }
  int s = (l + r) / 2;
  if (t <= s)
    upd(k, l, s, v, t, 2 * ind);
  else
    upd(k, s + 1, r, v, t, 2 * ind + 1);
  seg[k][ind] += v;
}
int nsum(int k, int l, int r, int lt, int rt, int ind) {
  if (l >= lt && r <= rt) return seg[k][ind];
  if (r < lt || l > rt) return 0;
  int s = (l + r) / 2;
  return nsum(k, l, s, lt, rt, 2 * ind) +
         nsum(k, s + 1, r, lt, rt, 2 * ind + 1);
}
int main() {
  int n, k;
  long long res = 0;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &a[i].second.second, &a[i].second.first, &a[i].first);
  }
  for (int i = 0; i < n; i++) {
    zb.push_back(a[i].second.second);
    zb.push_back(a[i].second.second - a[i].second.first);
    zb.push_back(a[i].second.second + a[i].second.first);
  }
  sort(zb.begin(), zb.end());
  for (int i = 0; i < zb.size(); i++) m[zb[i]] = i;
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    iq[i] = a[i].first;
    rg[i] = a[i].second.first;
    x[i] = m[a[i].second.second];
    lk[i] = m[a[i].second.second - rg[i]];
    rk[i] = m[a[i].second.second + rg[i]];
  }
  for (int i = 0; i < n; i++)
    if (i == n - 1 || iq[i] != iq[i + 1]) {
      b.clear();
      for (int j = i; j >= 0 && iq[i] - iq[j] <= k; j--) b.push_back(j);
      sort(b.begin(), b.end(), cmp);
      for (int j = 0; j < b.size(); j++) {
        if (iq[b[j]] == iq[i]) {
          res += nsum(0, 0, 3 * n, lk[b[j]], rk[b[j]], 1) +
                 nsum(1, 0, 3 * n, lk[b[j]], rk[b[j]], 1);
          upd(0, 0, 3 * n, 1, x[b[j]], 1);
        } else {
          res += nsum(0, 0, 3 * n, lk[b[j]], rk[b[j]], 1);
          upd(1, 0, 3 * n, 1, x[b[j]], 1);
        }
      }
      for (int j = 0; j < b.size(); j++) {
        if (iq[b[j]] == iq[i])
          upd(0, 0, 3 * n, -1, x[b[j]], 1);
        else
          upd(1, 0, 3 * n, -1, x[b[j]], 1);
      }
    }
  printf("%I64d", res);
}