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 = 200010;
int n, k, x[N], R[N], q[N], a, b;
vector<int> Q;
vector<int> v[N], seg[N];
vector<pair<int, int> > v2, v3;
long long ans = 0, d = 0;
int iq, Idx;
int update(int s, int e, int idx) {
  if (s > Idx || e < Idx) return seg[iq][idx];
  if (s == e) return ++seg[iq][idx];
  return seg[iq][idx] = update(s, ((s + e) >> 1), (idx << 1)) +
                        update(((s + e) >> 1) + 1, e, (idx << 1) + 1);
}
int l, r;
int getsum(int s, int e, int idx) {
  if (s > r || e < l) return 0;
  if (s >= l && e <= r) return seg[iq][idx];
  return getsum(s, ((s + e) >> 1), (idx << 1)) +
         getsum(((s + e) >> 1) + 1, e, (idx << 1) + 1);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &x[i], &R[i], &q[i]);
    Q.push_back(q[i]);
  }
  sort(Q.begin(), Q.end());
  Q.resize(unique(Q.begin(), Q.end()) - Q.begin());
  for (int i = 0; i < n; i++) {
    q[i] = lower_bound(Q.begin(), Q.end(), q[i]) - Q.begin();
    v[q[i]].push_back(x[i]);
    v2.push_back(make_pair(x[i], i));
    v3.push_back(make_pair(x[i] - R[i], i));
  }
  sort(v2.begin(), v2.end());
  sort(v3.begin(), v3.end());
  for (int i = 0; i < (int)Q.size(); i++) {
    sort(v[i].begin(), v[i].end());
    v[i].resize(unique(v[i].begin(), v[i].end()) - v[i].begin());
    seg[i].resize((int)v[i].size() * 4, 0);
  }
  int j = 0;
  for (int i = 0; i < (int)v2.size(); i++) {
    while (j < (int)v3.size() && v3[j].first <= v2[i].first) {
      iq = q[v3[j].second];
      Idx = lower_bound(v[iq].begin(), v[iq].end(), x[v3[j].second]) -
            v[iq].begin();
      update(0, (int)v[iq].size() - 1, 1);
      j++;
    }
    a = q[v2[i].second];
    while (a < (int)Q.size() && Q[a] - Q[q[v2[i].second]] <= k) {
      l = lower_bound(v[a].begin(), v[a].end(), x[v2[i].second]) - v[a].begin();
      r = upper_bound(v[a].begin(), v[a].end(),
                      x[v2[i].second] + R[v2[i].second]) -
          v[a].begin() - 1;
      if (r >= l) {
        iq = a;
        ans += getsum(0, (int)v[a].size() - 1, 1);
      }
      if (l < (int)v[a].size() && v[a][l] == x[v2[i].second]) {
        r = l;
        d += getsum(0, (int)v[a].size() - 1, 1);
      }
      a++;
    }
    a = q[v2[i].second] - 1;
    while (a >= 0 && Q[q[v2[i].second]] - Q[a] <= k) {
      l = lower_bound(v[a].begin(), v[a].end(), x[v2[i].second]) - v[a].begin();
      r = upper_bound(v[a].begin(), v[a].end(),
                      x[v2[i].second] + R[v2[i].second]) -
          v[a].begin() - 1;
      if (r >= l) {
        iq = a;
        ans += getsum(0, (int)v[a].size() - 1, 1);
      }
      if (l < (int)v[a].size() && v[a][l] == x[v2[i].second]) {
        r = l;
        d += getsum(0, (int)v[a].size() - 1, 1);
      }
      a--;
    }
  }
  d -= n;
  cout << ans - n - d / 2 << endl;
  return 0;
}