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 = 1e5 + 5;
int x[N], r[N], q[N];
int bit[N];
vector<int> Hash;
long long ans = 0;
int k;
inline int getid(int x) {
  return lower_bound(Hash.begin(), Hash.end(), x) - Hash.begin() + 1;
}
struct P {
  int x, r, q;
  P() {}
  P(int _x, int _r, int _q) { x = _x, r = _r, q = _q; }
  friend bool operator<(const P &a, const P &b) {
    if (a.r == b.r) return a.q < b.q;
    return a.r < b.r;
  }
};
inline bool cmp(const P &a, const P &b) { return a.q < b.q; }
inline int lowbit(int x) { return x & -x; }
inline void add(int x, int val) {
  while (x < N) bit[x] += val, x += lowbit(x);
}
inline int sum(int x) {
  int res = 0;
  while (x) res += bit[x], x -= lowbit(x);
  return res;
}
inline void modify(int x) {
  while (x < N) bit[x] = 0, x += lowbit(x);
}
void cdq(vector<P> &a) {
  int len = a.size();
  if (len <= 1) return;
  vector<P> b(a.begin(), a.begin() + len / 2);
  vector<P> c(a.begin() + len / 2, a.end());
  cdq(c);
  cdq(b);
  sort(b.begin(), b.end(), cmp);
  sort(c.begin(), c.end(), cmp);
  int l = 0, r = 0;
  for (int i = 0; i < b.size(); i++) {
    while (r < c.size() && c[r].q <= b[i].q + k) add(getid(c[r].x), 1), r++;
    while (l < r && c[l].q < b[i].q - k) add(getid(c[l].x), -1), l++;
    int x =
        upper_bound(Hash.begin(), Hash.end(), b[i].x + b[i].r) - Hash.begin();
    int y =
        lower_bound(Hash.begin(), Hash.end(), b[i].x - b[i].r) - Hash.begin();
    ans += sum(x) - sum(y);
  }
  for (int i = l; i < r; i++) modify(getid(c[i].x));
}
int main() {
  int n;
  scanf("%d%d", &n, &k);
  int x, r, q;
  vector<P> vec;
  for (int i = 0; i < n; i++)
    scanf("%d%d%d", &x, &r, &q), vec.push_back(move(P(x, r, q))),
        Hash.push_back(x);
  sort(vec.begin(), vec.end());
  sort(Hash.begin(), Hash.end());
  Hash.erase(unique(Hash.begin(), Hash.end()), Hash.end());
  cdq(vec);
  printf("%lld\n", ans);
  return 0;
}