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;
inline int Read() {
  int x = 0;
  char y;
  do y = getchar();
  while (y < '0' || y > '9');
  do x = x * 10 + y - '0', y = getchar();
  while (y >= '0' && y <= '9');
  return x;
}
long long ans;
map<int, int> rt;
int c[5000050][2], Cnt[5000050], wz[100050], r[100050], v[100050], n, m, st;
pair<int, int> li[100050 * 2];
void Delete(int x, int y, int z, int o) {
  Cnt[z]--;
  if (x == y) return;
  int mid = x + y >> 1;
  if (o <= mid)
    Delete(x, mid, c[z][0], o);
  else
    Delete(mid + 1, y, c[z][1], o);
  return;
}
int Insert(int x, int y, int z, int o) {
  if (!z) z = ++st;
  Cnt[z]++;
  int mid = x + y >> 1;
  if (x != y)
    if (o <= mid)
      c[z][0] = Insert(x, mid, c[z][0], o);
    else
      c[z][1] = Insert(mid + 1, y, c[z][1], o);
  return z;
}
int Query(int x, int y, int z, int o, int p) {
  if (x == o && y == p) return Cnt[z];
  if (!z) return 0;
  int mid = x + y >> 1;
  if (p <= mid)
    return Query(x, mid, c[z][0], o, p);
  else if (o > mid)
    return Query(mid + 1, y, c[z][1], o, p);
  else
    return Query(x, mid, c[z][0], o, mid) +
           Query(mid + 1, y, c[z][1], mid + 1, p);
}
void Solve() {
  for (int i = 1; i <= n * 2; i++)
    if (li[i].second > 0) {
      int _rt = rt[v[li[i].second]];
      Delete(0, (int)1e9, _rt, wz[li[i].second]);
    } else {
      int k = -li[i].second;
      int le = max(wz[k] - r[k], 0);
      for (int j = -m; j <= m; j++) {
        int _rt = rt[v[k] + j];
        if (!_rt) continue;
        ans += Query(0, (int)1e9, _rt, le, wz[k]);
      }
      int _rt = rt[v[k]];
      rt[v[k]] = Insert(0, (int)1e9, _rt, wz[k]);
    }
  return;
}
int main() {
  n = Read();
  m = Read();
  for (int i = 1; i <= n; i++) {
    wz[i] = Read();
    r[i] = Read();
    v[i] = Read();
    li[i * 2 - 1] = make_pair(wz[i] + r[i], i);
    li[i * 2] = make_pair(wz[i], -i);
  }
  sort(li + 1, li + 2 * n + 1);
  Solve();
  cout << ans << endl;
  return 0;
}