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.
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 20;
int n, K;
struct Node {
  int sum;
  Node *lson, *rson;
  Node() { sum = 0, lson = rson = NULL; }
};
map<int, Node *> G;
struct Robot {
  int x, r, q;
};
vector<Robot> vec;
int ers[maxn];
int pos[maxn];
void ins(int pos, int val, int l, int r, Node *&o) {
  if (o == NULL) o = new Node();
  if (l == r) {
    o->sum += val;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    ins(pos, val, l, mid, o->lson);
  else
    ins(pos, val, mid + 1, r, o->rson);
  o->sum = 0;
  if (o->lson) o->sum += o->lson->sum;
  if (o->rson) o->sum += o->rson->sum;
}
int query(int L, int R, int l, int r, Node *&o) {
  if (o == NULL) return 0;
  if (L <= l && r <= R) return o->sum;
  int mid = (l + r) >> 1;
  if (R <= mid) return query(L, R, l, mid, o->lson);
  if (mid < L) return query(L, R, mid + 1, r, o->rson);
  return query(L, R, l, mid, o->lson) + query(L, R, mid + 1, r, o->rson);
}
void work() {
  scanf("%d%d", &n, &K);
  vec = vector<Robot>(n);
  for (int i = 0; i < n; i++) {
    int x, r, q;
    scanf("%d%d%d", &x, &r, &q);
    vec[i] = (Robot){x, r, q};
  }
  iota(ers, ers + n, 0);
  iota(pos, pos + n, 0);
  sort(ers, ers + n,
       [](int x, int y) { return vec[x].x + vec[x].r < vec[y].x + vec[y].r; });
  sort(pos, pos + n, [](int x, int y) { return vec[x].x < vec[y].x; });
  long long ans = 0;
  for (int i = 0, j = 0; i < n; i++) {
    int u = pos[i], v = ers[j];
    int p = vec[u].x;
    while (j < n && vec[v].x + vec[v].r < p) {
      ins(vec[v].x, -1, 0, 1e9, G[vec[v].q]);
      v = ers[++j];
    }
    for (int k = -K; k <= K; k++)
      ans += query(vec[u].x - vec[u].r, vec[u].x, 0, 1e9, G[k + vec[u].q]);
    if (G.find(vec[u].q) == G.end()) {
      G[vec[u].q] = new Node();
    }
    ins(vec[u].x, 1, 0, 1e9, G[vec[u].q]);
  }
  cout << ans << endl;
}
int main() {
  work();
  return 0;
}
