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 di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
int lg(int x) {
  int res = 0;
  for (int i = 0; i < x; i++) {
    long long GT = (1 << i);
    if (GT <= x) {
      res = i;
    } else {
      return res;
    }
  }
  return res;
}
int GCD(int a, int b) {
  if (b == 0) {
    return abs(a);
  }
  return GCD(b, a % b);
}
long long sqr(long long x) { return x * x; }
long long nhan(long long a, long long b, long long module) {
  a %= module;
  b %= module;
  long long q = (long double)a * b / module;
  long long r = (a * b - q * module) % module;
  if (r < 0) {
    r += module;
  }
  return r;
}
long long MU(long long a, long long n, long long module) {
  long long res = 1;
  for (; n; n = n >> 1, a = nhan(a, a, module)) {
    if (n & 1) {
      res = nhan(res, a, module);
    }
  }
  return res;
}
void hamZ(string S, int z[]) {
  int n = S.size();
  for (int i = 0; i <= n; i++) {
    z[i] = 0;
  }
  int L = 1, R = 1;
  for (int i = 2; i <= n; i++) {
    if (i <= R) {
      z[i] = min(z[i - L + 1], R - i + 1);
    }
    while (i + z[i] <= n && S[z[i]] == S[i + z[i] - 1]) {
      z[i]++;
    }
    if (i + z[i] - 1 > R) {
      R = i + z[i] - 1;
      L = i;
    }
  }
}
void Sang(int N, int p[]) {
  for (int i = 0; i <= N; i++) {
    p[i] = 0;
  }
  for (int i = 2; i <= N; i++) {
    p[i] = i;
  }
  int gt = sqrt(N);
  for (int i = 2; i <= N; i++) {
    if (p[i] == i) {
      if (i > gt) {
        continue;
      }
      int j = i * i;
      while (j <= N) {
        p[j] = i;
        j += i;
      }
    }
  }
}
const int N = 1e5 + 5;
const long long oo = 1e15;
const long double sodu = 1e-6;
const int module = 998244353;
const int M = 1e9 + 7;
const int NN = (1 << 16);
struct node {
  int x, R, IQ;
};
bool cmp(node a, node b) { return a.x < b.x; }
bool ss(node a, node b) {
  if (a.R != b.R) {
    return a.R < b.R;
  }
  return a.x < b.x;
}
int n, K, m;
node a[N];
vector<int> A[N], B, IT[N * 4];
vector<int> CC;
void nhap() {
  cin >> n >> K;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].R >> a[i].IQ;
    CC.push_back(a[i].IQ);
  }
  sort(CC.begin(), CC.end());
  CC.resize(unique(CC.begin(), CC.end()) - CC.begin());
  m = CC.size();
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    int x = lower_bound(CC.begin(), CC.end(), a[i].IQ) - CC.begin();
    A[x].push_back(a[i].x);
  }
}
void update(int mask, int i, int l, int r, int u) {
  if (l > u || r < u) {
    return;
  }
  if (l == r) {
    IT[mask][i]++;
    return;
  }
  int mid = (l + r) >> 1;
  update(mask, i << 1, l, mid, u);
  update(mask, i << 1 | 1, mid + 1, r, u);
  IT[mask][i] = IT[mask][i << 1] + IT[mask][i << 1 | 1];
}
int Get(int mask, int i, int l, int r, int u, int v) {
  if (l > v || r < u) {
    return 0;
  }
  if (l >= u && r <= v) {
    return IT[mask][i];
  }
  int mid = (l + r) >> 1;
  int left = Get(mask, i << 1, l, mid, u, v);
  int right = Get(mask, i << 1 | 1, mid + 1, r, u, v);
  return left + right;
}
void solve() {
  sort(a + 1, a + 1 + n, ss);
  for (int i = 0; i < m; i++) {
    if (A[i].size() == 0) {
      continue;
    }
    sort(A[i].begin(), A[i].end());
    A[i].resize(unique(A[i].begin(), A[i].end()) - A[i].begin());
    IT[i].resize(A[i].size() * 4 + 2);
  }
  long long Res = 0;
  for (int i = n; i >= 1; i--) {
    for (int j = -K; j <= K; j++) {
      int vc = a[i].IQ + j;
      if (vc >= 0 && vc <= 1000000000) {
        int posB = lower_bound(CC.begin(), CC.end(), vc) - CC.begin();
        if (posB == CC.size()) {
          continue;
        }
        if (CC[posB] != vc) {
          continue;
        }
        if (A[posB].size() == 0) {
          continue;
        }
        int posR =
            upper_bound(A[posB].begin(), A[posB].end(), a[i].x + a[i].R) -
            A[posB].begin();
        int posL =
            lower_bound(A[posB].begin(), A[posB].end(), a[i].x - a[i].R) -
            A[posB].begin();
        if (posL >= posR) {
          continue;
        }
        Res += Get(posB, 1, 0, A[posB].size() - 1, posL, posR - 1);
      }
    }
    int posB = lower_bound(CC.begin(), CC.end(), a[i].IQ) - CC.begin();
    int pos =
        lower_bound(A[posB].begin(), A[posB].end(), a[i].x) - A[posB].begin();
    update(posB, 1, 0, A[posB].size() - 1, pos);
  }
  cout << Res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  nhap();
  solve();
}