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 MAX = 3e5 + 5;
struct p {
  int x, id;
  bool operator<(const p &a) const { return x < a.x; }
} A[MAX];
int n, k, cnt, ID, Mr;
long long ans;
int s[MAX], nL[MAX], nR[MAX], nX[MAX], L[MAX], R[MAX], X[MAX], q[MAX], _[MAX],
    id[MAX], _id[MAX], a[MAX], b[MAX];
bool cmp(int a, int b) { return _[a] < _[b]; }
bool cmp1(int a, int b) { return q[a] < q[b]; }
int lowbit(int x) { return x & -x; }
void change(int x, int d) {
  for (int i = x; i <= ID; i += lowbit(i)) s[i] += d;
}
int ask(int x) {
  int ans = 0;
  for (int i = x; i; i -= lowbit(i)) ans += s[i];
  return ans;
}
int ask(int l, int r) { return ask(r) - ask(l - 1); }
int read() {
  int x(0);
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    ;
  for (; isdigit(ch); x = x * 10 + ch - 48, ch = getchar())
    ;
  return x;
}
void Solve(int l = 1, int r = n) {
  if (l == r) return;
  int mid(l + r >> 1), _L = mid + 1, _R = mid + 1;
  for (int i = l; i <= r; ++i) id[i] = _id[i];
  sort(id + l, id + mid + 1, cmp1), sort(id + mid + 1, id + r + 1, cmp1);
  for (int i = l; i <= mid; ++i) {
    while (_L <= r && q[id[_L]] < q[id[i]] - k) change(X[id[_L]], -1), ++_L;
    while (_R <= r && q[id[_R]] <= q[id[i]] + k) change(X[id[_R]], 1), ++_R;
    ans += ask(L[id[i]], R[id[i]]);
  }
  while (_L < _R) change(X[id[_L]], -1), ++_L;
  Solve(l, mid), Solve(mid + 1, r);
}
int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; ++i)
    _id[i] = i, nX[i] = read(), Mr = max(Mr, _[i] = read()), q[i] = read(),
    A[++cnt] = (p){nX[i], i}, A[++cnt] = (p){nL[i] = max(nX[i] - _[i], 0), i},
    A[++cnt] = (p){nR[i] = nX[i] + _[i], i};
  sort(A + 1, A + 1 + cnt), A[0].x = -1;
  for (int i = 1; i <= cnt; ++i) {
    if (A[i].x != A[i - 1].x) ++ID;
    if (nX[A[i].id] == A[i].x) X[A[i].id] = ID;
    if (nL[A[i].id] == A[i].x) L[A[i].id] = ID;
    if (nR[A[i].id] == A[i].x) R[A[i].id] = ID;
  }
  return sort(_id + 1, _id + 1 + n, cmp), Solve(), printf("%I64d", ans), 0;
}