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 = 3e5 + 5;
vector<int> v;
pair<int, pair<int, int> > arr[N];
vector<int> seg[N << 2];
vector<int> BIT[N << 2];
int MX, n;
void increase(int id, int i, int delta = 1) {
  for (; i < BIT[id].size(); i |= i + 1) BIT[id][i] += delta;
}
int sum(int id, int i) {
  int ans = 0;
  i = min(i, (int)BIT[id].size() - 1);
  for (; i >= 0; i = (i & (i + 1)) - 1) ans += BIT[id][i];
  return ans;
}
int getsum(int id, int L, int R) { return sum(id, R) - sum(id, L - 1); }
void add(int val, int idx, int id = 1, int l = 0, int first = MX) {
  seg[id].push_back(val);
  if (first - l < 2) return;
  int mid = (l + first) / 2;
  if (idx < mid)
    add(val, idx, id * 2, l, mid);
  else
    add(val, idx, id * 2 + 1, mid, first);
}
void inc(int val, int idx, int id = 1, int l = 0, int first = MX) {
  int index =
      lower_bound(seg[id].begin(), seg[id].end(), val) - seg[id].begin();
  increase(id, index);
  if (first - l < 2) return;
  int mid = (l + first) / 2;
  if (idx < mid)
    inc(val, idx, id * 2, l, mid);
  else
    inc(val, idx, id * 2 + 1, mid, first);
}
void build(int id = 1, int l = 0, int first = MX) {
  if (!seg[id].size()) return;
  sort(seg[id].begin(), seg[id].end());
  seg[id].resize(unique(seg[id].begin(), seg[id].end()) - seg[id].begin());
  BIT[id].resize(seg[id].size() + 1);
  if (first - l < 2) return;
  int mid = (l + first) / 2;
  build(id * 2, l, mid);
  build(id * 2 + 1, mid, first);
}
int query(int qs, int qe, int from, int to, int id = 1, int l = 0,
          int first = MX) {
  if (qs >= first or l >= qe) return 0;
  if (BIT[id].size() == 0) return 0;
  if (qs <= l && first <= qe) {
    int idxfrom =
        lower_bound(seg[id].begin(), seg[id].end(), from) - seg[id].begin();
    int idxto =
        upper_bound(seg[id].begin(), seg[id].end(), to) - seg[id].begin() - 1;
    return getsum(id, idxfrom, idxto);
  }
  int mid = (l + first) / 2;
  return query(qs, qe, from, to, id * 2, l, mid) +
         query(qs, qe, from, to, id * 2 + 1, mid, first);
}
int F(int val) { return lower_bound(v.begin(), v.end(), val) - v.begin(); }
int main() {
  int k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &arr[i].second.first, &arr[i].first, &arr[i].second.second);
    v.push_back(arr[i].second.first);
    v.push_back(arr[i].second.first - arr[i].first);
    v.push_back(arr[i].second.first + arr[i].first);
  }
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  MX = v.size();
  sort(arr, arr + n);
  reverse(arr, arr + n);
  for (int i = 0; i < n; i++) {
    add(arr[i].second.second, F(arr[i].second.first));
  }
  build();
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += query(F(arr[i].second.first - arr[i].first),
                 F(arr[i].second.first + arr[i].first) + 1,
                 arr[i].second.second - k, arr[i].second.second + k);
    inc(arr[i].second.second, F(arr[i].second.first));
  }
  printf("%lld\n", ans);
  return 0;
}