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 long long MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1};
tuple<int, int, int> a[100000];
map<int, vector<int> > M, T;
inline int UPPER(int i, int x) {
  vector<int> &v = T[i];
  return upper_bound(v.begin(), v.end(), x) - v.begin();
}
inline int LOWER(int i, int x) {
  vector<int> &v = T[i];
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
void upd(int i, vector<int> &tree) {
  int n = tree.size() - 5;
  while (i <= n + 2) {
    tree[i]++;
    i += (i & -i);
  }
}
int sum(int i, vector<int> &tree) {
  int c = 0;
  while (i > 0) {
    c += tree[i];
    i -= (i & -i);
  }
  return c;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  long long ans = 0;
  for (int(i) = (0); (i) <= (n - 1); (i) += (1)) {
    int x, r, q;
    scanf("%d%d%d", &x, &r, &q);
    T[q].push_back(x);
    a[i] = tuple<int, int, int>(r, x, q);
  }
  for (auto it = T.begin(); it != T.end(); it++) {
    sort(it->second.begin(), it->second.end());
    int N = it->second.size();
    M[it->first].resize(N + 5);
  }
  sort(a, a + n);
  for (int(i) = (n - 1); (i) >= (0); (i) -= (1)) {
    int x, r, q;
    tie(r, x, q) = a[i];
    for (int(K) = (q - k); (K) <= (q + k); (K) += (1)) {
      vector<int> &vv = M[K];
      if (vv.empty()) continue;
      int L = LOWER(K, x - r), R = UPPER(K, x + r);
      ans += sum(R, vv) - sum(L, vv);
    }
    upd(LOWER(q, x) + 1, M[q]);
  }
  printf("%lld", ans);
}