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;
struct Query {
  int l, r, b, q;
};
int N, K;
int X[100005], R[100005], Q[100005];
int X2[100005], R2[100005], Q2[100005];
int Xrad[100005], SA[100005], SA2[100005];
set<int> Avail;
vector<Query> Qs;
bool CMP(Query i, Query j) { return i.b < j.b; }
bool CMP2(int i, int j) { return Xrad[i] < Xrad[j]; }
bool CMP3(int i, int j) { return X2[i] < X2[j]; }
unordered_map<int, int> Root;
int nn = 1;
int va[20 * 100005], lc[20 * 100005], rc[20 * 100005];
void up(int& P, int idx, int val, int L = 0, int R = N - 1) {
  if (!P) P = nn++;
  va[P]++;
  if (L == R) return;
  int Mid = (L + R) >> 1;
  if (idx <= Mid)
    up(lc[P], idx, val, L, Mid);
  else
    up(rc[P], idx, val, Mid + 1, R);
}
int Count(int QL, int QR, int& P, int L = 0, int R = N - 1) {
  if (!P || R < QL || QR < L) return 0;
  if (QL <= L && R <= QR) return va[P];
  int Mid = (L + R) >> 1;
  return Count(QL, QR, lc[P], L, Mid) + Count(QL, QR, rc[P], Mid + 1, R);
}
void Update(int idx) { up(Root[Q[idx]], idx, Q[idx]); }
int Query(int QL, int QR, int q) { return Count(QL, QR, Root[q]); }
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%d%d%d", &X2[i], &R2[i], &Q2[i]);
    Avail.insert(Q2[i]);
  }
  iota(SA2, SA2 + N, 0);
  sort(SA2, SA2 + N, CMP3);
  for (int i = 0; i < N; i++) {
    X[i] = X2[SA2[i]];
    R[i] = R2[SA2[i]];
    Q[i] = Q2[SA2[i]];
    Xrad[i] = X[i] - R[i];
  }
  int st, en;
  for (int i = 0; i < N; i++) {
    st = i + 1;
    en = upper_bound(X, X + N, X[i] + R[i]) - X - 1;
    if (en < st) continue;
    for (int j = Q[i] - K; j <= Q[i] + K; j++)
      if (Avail.find(j) != Avail.end()) Qs.push_back({st, en, X[i], j});
  }
  iota(SA, SA + N, 0);
  sort(SA, SA + N, CMP2);
  sort(Qs.begin(), Qs.end(), CMP);
  int ptr = 0;
  long long Ans = 0LL;
  for (auto j : Qs) {
    while (ptr < N && Xrad[SA[ptr]] <= j.b) Update(SA[ptr++]);
    Ans += Query(j.l, j.r, j.q);
  }
  printf("%I64d\n", Ans);
}