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 P = 1e9 + 7, INF = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
  long long r = 1 % P;
  for (a %= P; n; a = a * a % P, n >>= 1)
    if (n & 1) r = r * a % P;
  return r;
}
long long inv(long long first) {
  return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;
}
inline int rd() {
  int first = 0;
  char p = getchar();
  while (p < '0' || p > '9') p = getchar();
  while (p >= '0' && p <= '9') first = first * 10 + p - '0', p = getchar();
  return first;
}
const int N = 1e6 + 10;
int n, k, tot, b[N];
struct _ {
  int type, first, second;
  void pr() { printf("tp=%d,x=%d,y=%d\n", type, first, second); }
  bool operator<(const _& rhs) const {
    if (first != rhs.first) return first < rhs.first;
    if (second != rhs.second) return second < rhs.second;
    return type < rhs.type;
  }
} e[N];
struct __ {
  int first, r, q;
} a[N];
long long ans;
int c[N], tim[N], clk;
void add(int first) {
  for (; first <= *b; first += first & -first)
    tim[first] == clk ? ++c[first] : c[first] = 1, tim[first] = clk;
}
int qry(int first) {
  int r = 0;
  for (; first; first ^= first & -first) tim[first] == clk ? r += c[first] : 0;
  return r;
}
void merge(int l, int r) {
  if (l == r) return;
  merge(l, ((l + r) >> 1)), merge(((l + r) >> 1) + 1, r);
  int now = l;
  ++clk;
  for (int i = ((l + r) >> 1) + 1; i <= r; ++i) {
    while (now <= ((l + r) >> 1) && e[now].first <= e[i].first) {
      if (e[now].type == 0) add(e[now].second);
      ++now;
    }
    if (e[i].type == 1) {
      ans += qry(e[i].second);
    } else if (e[i].type == 2)
      ans -= qry(e[i].second);
  }
  inplace_merge(e + l, e + ((l + r) >> 1) + 1, e + r + 1);
}
int id(int first) { return lower_bound(b + 1, b + 1 + *b, first) - b; }
void add(int first, int second) {
  second = id(second);
  e[++tot] = {0, first, second};
}
void qry(int x1, int y1, int x2, int y2) {
  y1 = id(y1), y2 = id(y2);
  e[++tot] = {1, x2, y2};
  e[++tot] = {1, x1 - 1, y1 - 1};
  e[++tot] = {2, x1 - 1, y2};
  e[++tot] = {2, x2, y1 - 1};
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &a[i].first, &a[i].r, &a[i].q);
    b[++*b] = a[i].q, b[++*b] = a[i].q + k, b[++*b] = a[i].q - k - 1;
  }
  sort(a + 1, a + 1 + n, [](__ a, __ b) { return a.r > b.r; });
  sort(b + 1, b + 1 + *b), *b = unique(b + 1, b + 1 + *b) - b - 1;
  for (int i = 1; i <= n; ++i) {
    qry(a[i].first - a[i].r, a[i].q - k, a[i].first + a[i].r, a[i].q + k);
    add(a[i].first, a[i].q);
  }
  merge(1, tot);
  printf("%lld\n", ans);
}