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;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x, int p, int MOD) {
  if (p == 0) return 1 % MOD;
  if (p == 1) return x % MOD;
  int res = power(x, p / 2, MOD);
  res = (long long)res * res % MOD;
  if (p & 1) res = (long long)res * x % MOD;
  return res;
}
struct CompressedBit {
  vector<int> indices;
  vector<int> T;
  int n;
  CompressedBit() {}
  CompressedBit(const vector<int>& ind)
      : indices(ind), T(ind.size() + 2), n(T.size()) {}
  CompressedBit(const vector<int>& a, const vector<int>& b) {
    merge((a).begin(), (a).end(), (b).begin(), (b).end(),
          back_inserter(indices));
    T = vector<int>(indices.size() + 2);
    n = T.size();
  }
  friend CompressedBit operator+(const CompressedBit& a,
                                 const CompressedBit& b) {
    return CompressedBit(a.indices, b.indices);
  }
  int idx(int i) {
    auto res =
        upper_bound((indices).begin(), (indices).end(), i) - indices.begin();
    return res;
  }
  void _add(int i, int x) {
    for (i++; i < n; i += (i & -i)) T[i] += x;
  }
  int _get(int i) {
    int res = 0;
    for (i++; i; i -= (i & -i)) res += T[i];
    return res;
  }
  void add(int i, int x) { _add(idx(i), x); }
  int get(int i) { return _get(idx(i)); }
};
const int N = 1e5 + 10;
CompressedBit t[4 * N];
vector<int> qis[N];
void build(int no, int l, int r) {
  if (l == r) {
    sort((qis[l]).begin(), (qis[l]).end());
    t[no] = CompressedBit(qis[l]);
  } else {
    int mid = (l + r) / 2;
    build(2 * no, l, mid);
    build(2 * no + 1, mid + 1, r);
    t[no] = t[2 * no] + t[2 * no + 1];
  }
}
void update(int no, int l, int r, int x, int qi) {
  t[no].add(qi, +1);
  if (l != r) {
    int mid = (l + r) / 2;
    if (x <= mid)
      update(2 * no, l, mid, x, qi);
    else
      update(2 * no + 1, mid + 1, r, x, qi);
  }
}
int query(int no, int l, int r, int i, int j, int a, int b) {
  if (j < l || r < i) return 0;
  if (i <= l && r <= j) {
    return t[no].get(b) - t[no].get(a - 1);
  } else {
    int mid = (l + r) / 2;
    return query(2 * no, l, mid, i, j, a, b) +
           query(2 * no + 1, mid + 1, r, i, j, a, b);
  }
}
struct Robot {
  int x, r, qi;
  bool operator<(const Robot& rhs) const { return r > rhs.r; }
};
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, K;
  cin >> n >> K;
  set<int> dis;
  vector<Robot> robots;
  for (int i = 0; i < n; i++) {
    int x, r, qi;
    cin >> x >> r >> qi;
    robots.push_back({x, r, qi});
    dis.insert(x);
  }
  vector<int> comp((dis).begin(), (dis).end());
  for (Robot& rob : robots)
    rob.x = lower_bound((comp).begin(), (comp).end(), rob.x) - comp.begin();
  sort((robots).begin(), (robots).end());
  for (Robot& rob : robots) qis[rob.x].push_back(rob.qi);
  int M = comp.size();
  build(1, 0, M - 1);
  long long ans = 0;
  for (const auto& rob : robots) {
    int ox = comp[rob.x];
    int R = upper_bound((comp).begin(), (comp).end(), ox + rob.r) -
            comp.begin() - 1;
    int L =
        lower_bound((comp).begin(), (comp).end(), ox - rob.r) - comp.begin();
    ans += query(1, 0, M - 1, L, R, rob.qi - K, rob.qi + K);
    update(1, 0, M - 1, rob.x, rob.qi);
  }
  cout << ans << endl;
}