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>
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 3e5 + 10;
int n, k, siz;
int ans[maxn];
vector<int> vx, viq;
int bit[maxn];
int lowbit(int x) { return x & -x; }
void update(int iq, int flag) {
  for (int i = iq; i < maxn; i += lowbit(i)) bit[i] += flag;
}
int query(int iq) {
  int ans = 0;
  for (int i = iq; i > 0; i -= lowbit(i)) ans += bit[i];
  return ans;
}
struct Node {
  int iq, pos, flag, low, high, id, r;
  Node() { iq = pos = flag = low = high = id = r = 0; }
  Node(int iq, int pos, int flag, int low, int high, int id, int r) {
    this->iq = iq;
    this->pos = pos;
    this->flag = flag;
    this->low = low;
    this->high = high;
    this->id = id;
    this->r = r;
  }
  bool operator<(const Node &b) const {
    if (pos == b.pos) return flag < b.flag;
    return pos < b.pos;
  }
} b[maxn], tmp[maxn];
int cmpinit(const Node &a, const Node &b) {
  if (a.r == b.r) return a.flag < b.flag;
  return a.r > b.r;
}
void cdq(int l, int r) {
  if (l == r) return;
  cdq(l, (l + r) / 2);
  cdq((l + r) / 2 + 1, r);
  sort(b + l, b + (l + r) / 2 + 1);
  sort(b + (l + r) / 2 + 1, b + r + 1);
  int p = l, q = (l + r) / 2 + 1;
  while (p <= (l + r) / 2 && q <= r) {
    if (b[p] < b[q]) {
      if (!b[p].flag) update(b[p].iq, 1);
      p++;
    } else {
      if (b[q].flag) {
        int sum1 = query(b[q].low), sum2 = query(b[q].high);
        ans[b[q].id] += (sum2 - sum1) * (b[q].flag == 1 ? -1 : 1);
      }
      q++;
    }
  }
  while (p <= (l + r) / 2) {
    if (!b[p].flag) update(b[p].iq, 1);
    p++;
  }
  while (q <= r) {
    if (b[q].flag) {
      int sum1 = query(b[q].low), sum2 = query(b[q].high);
      ans[b[q].id] += (sum2 - sum1) * (b[q].flag == 1 ? -1 : 1);
    }
    q++;
  }
  p = l;
  while (p <= (l + r) / 2) {
    if (!b[p].flag) update(b[p].iq, -1);
    p++;
  }
}
int checkiq(int x) {
  int l = 0, r = viq.size() - 1;
  while (1) {
    if (l + 1 >= r) {
      if (x == viq[l]) return l + 1;
      return r + 1;
    }
    if (viq[(l + r) / 2] < x)
      l = (l + r) / 2 + 1;
    else
      r = (l + r) / 2;
  }
}
int checkx(int x) {
  int l = 0, r = vx.size() - 1;
  while (1) {
    if (l + 1 >= r) {
      if (x == vx[l]) return l + 1;
      return r + 1;
    }
    if (vx[(l + r) / 2] < x)
      l = (l + r) / 2 + 1;
    else
      r = (l + r) / 2;
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    int x, r, iq;
    scanf("%d%d%d", &x, &r, &iq);
    tmp[i].pos = x;
    tmp[i].low = x - r - 1;
    tmp[i].iq = iq;
    tmp[i].r = r;
    vx.push_back(x);
    vx.push_back(x - r - 1);
    vx.push_back(x + r);
    viq.push_back(iq);
    viq.push_back(iq - k - 1);
    viq.push_back(iq + k);
  }
  sort(vx.begin(), vx.end());
  sort(viq.begin(), viq.end());
  vx.erase(unique(vx.begin(), vx.end()), vx.end());
  viq.erase(unique(viq.begin(), viq.end()), viq.end());
  sort(tmp + 1, tmp + n + 1, cmpinit);
  for (int i = 1; i <= n; i++) {
    b[++siz] =
        Node(checkiq(tmp[i].iq), checkx(tmp[i].pos), 0, 0, 0, i, tmp[i].r);
    b[++siz] = Node(0, checkx(tmp[i].low), 1, checkiq(tmp[i].iq - k - 1),
                    checkiq(tmp[i].iq + k), i, tmp[i].r);
    b[++siz] =
        Node(0, checkx(tmp[i].pos + tmp[i].r), 2, checkiq(tmp[i].iq - k - 1),
             checkiq(tmp[i].iq + k), i, tmp[i].r);
  }
  cdq(1, siz);
  long long sum = 0;
  for (int i = 1; i <= n; i++) sum += 1LL * (ans[i] - 1);
  printf("%lld\n", sum);
  return 0;
}