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 N = 1e5 + 10;
int n, k;
struct robot {
  int x, r, q, id;
} a[N];
priority_queue<robot> DauPhai;
long long numPair[N];
bool inTree[N];
bool operator<(robot i, robot j) { return i.x + i.r > j.x + j.r; }
bool cmpRobotX(const robot &i, const robot &j) { return i.x < j.x; }
bool cmpRobotQ(const robot &i, const robot &j) { return i.q < j.q; }
long long ans = 0ll;
int tree[N], treeQ[N];
int tblX[N];
int nX;
int queryTree(int tree[], int idx) {
  int sum = 0;
  for (; idx > 0; idx -= (idx & -idx)) sum += tree[idx];
  return sum;
}
int queryRange(int tree[], int u, int v) {
  if (u > v) return 0;
  return queryTree(tree, v) - queryTree(tree, u - 1);
}
void updateTree(int tree[], int idx, int delta) {
  for (; idx <= nX; idx += (idx & -idx)) tree[idx] += delta;
}
void zz() {}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &a[i].x, &a[i].r, &a[i].q);
    a[i].id = i;
  }
  sort(a + 1, a + n + 1, cmpRobotX);
  for (int i = 1; i <= n; ++i) tblX[i] = a[i].x;
  nX = (int)(unique(tblX + 1, tblX + n + 1) - (tblX + 1));
  sort(a + 1, a + n + 1, cmpRobotQ);
  int l = 1, r = 1;
  while (r <= n) {
    while (r <= n && a[r + 1].q == a[r].q) r++;
    r++;
    int qDangXet = a[r - 1].q;
    while (l <= n && qDangXet - a[l].q > k) l++;
    sort(a + l, a + r, cmpRobotX);
    for (int i = l; i < r; ++i) {
      while (!DauPhai.empty() && DauPhai.top().x + DauPhai.top().r < a[i].x) {
        robot to = DauPhai.top();
        updateTree(
            tree, (int)(lower_bound(tblX + 1, tblX + nX + 1, to.x) - tblX), -1);
        if (to.q == qDangXet)
          updateTree(treeQ,
                     (int)(lower_bound(tblX + 1, tblX + nX + 1, to.x) - tblX),
                     -1);
        inTree[to.id] = 0;
        DauPhai.pop();
      }
      if (a[i].q == qDangXet) {
        int idL =
            (int)(lower_bound(tblX + 1, tblX + nX + 1, a[i].x - a[i].r) - tblX);
        int idR = (int)(upper_bound(tblX + 1, tblX + nX + 1, a[i].x + a[i].r) -
                        1 - tblX);
        int tmp;
        numPair[a[i].id] += (tmp = queryRange(tree, idL, idR));
        if (a[i].id == 1 && tmp > 0) zz();
        ans += tmp;
      } else {
        int idL =
            (int)(lower_bound(tblX + 1, tblX + nX + 1, a[i].x - a[i].r) - tblX);
        int idR = (int)(upper_bound(tblX + 1, tblX + nX + 1, a[i].x + a[i].r) -
                        1 - tblX);
        int tmp;
        numPair[a[i].id] += (tmp = queryRange(treeQ, idL, idR));
        if (a[i].id == 1 && tmp > 0) zz();
        ans += tmp;
      }
      updateTree(
          tree, (int)(lower_bound(tblX + 1, tblX + nX + 1, a[i].x) - tblX), +1);
      if (a[i].q == qDangXet)
        updateTree(treeQ,
                   (int)(lower_bound(tblX + 1, tblX + nX + 1, a[i].x) - tblX),
                   +1);
      inTree[a[i].id] = 1;
      DauPhai.push(a[i]);
    }
    for (int i = l; i < r; ++i)
      if (inTree[a[i].id]) {
        updateTree(tree,
                   (int)(lower_bound(tblX + 1, tblX + nX + 1, a[i].x) - tblX),
                   -1);
        if (a[i].q == qDangXet)
          updateTree(treeQ,
                     (int)(lower_bound(tblX + 1, tblX + nX + 1, a[i].x) - tblX),
                     -1);
        inTree[a[i].id] = 0;
      }
    while (!DauPhai.empty()) DauPhai.pop();
    sort(a + l, a + r, cmpRobotQ);
  }
  printf("%I64d\n", ans);
  return 0;
}