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 GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const long long oo = 1e18 + 7, mod = 1e9 + 7;
const long long N = 1e5 + 5;
struct robots {
  long long pos, range, IQ, id;
} robot[N], robot2[N];
bool cmp2(long long a, long long b) { return robot2[a].pos < robot2[b].pos; }
bool cmp(robots a, robots b) {
  if (a.range != b.range)
    return a.range < b.range;
  else if (a.pos != b.pos)
    return a.pos < b.pos;
  else if (a.IQ != b.IQ)
    return a.IQ < b.IQ;
}
long long n, k, ans;
unordered_map<long long, vector<long long>> BIT;
unordered_map<long long, vector<long long>> segs;
unordered_map<long long, pair<long long, long long>> pos;
void update(long long pos, long long pos2, long long val) {
  for (; pos2 < BIT[pos].size(); pos2 += pos2 & -pos2) BIT[pos][pos2] += val;
}
long long get(long long pos, long long pos2) {
  long long ans = 0;
  for (; pos2; pos2 -= pos2 & -pos2) ans += BIT[pos][pos2];
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> robot[i].pos >> robot[i].range >> robot[i].IQ;
    robot[i].id = i;
    segs[robot[i].IQ].push_back(i);
    robot2[i] = robot[i];
  }
  sort(robot + 1, robot + n + 1, cmp);
  robot2[0].pos = -oo;
  for (auto it : segs) {
    it.second.push_back(0);
    sort(it.second.begin(), it.second.end(), cmp2);
    for (long long i = 1; i < it.second.size(); i++)
      pos[it.second[i]] = {it.first, i};
    for (long long i = 0; i < it.second.size(); i++)
      it.second[i] = robot2[it.second[i]].pos;
    for (long long i = 0; i < it.second.size(); i++) BIT[it.first].push_back(0);
    for (long long i = 1; i < it.second.size(); i++) update(it.first, i, 1);
    segs[it.first] = it.second;
  }
  for (long long i = 1; i <= n; i++) {
    if (i > 1)
      update(pos[robot[i - 1].id].first, pos[robot[i - 1].id].second, -1);
    for (long long j = robot[i].IQ - k; j <= robot[i].IQ + k; j++) {
      if (!segs[j].size()) continue;
      long long temp1 = lower_bound(segs[j].begin(), segs[j].end(),
                                    robot[i].pos - robot[i].range) -
                        segs[j].begin();
      long long temp2 = upper_bound(segs[j].begin(), segs[j].end(),
                                    robot[i].pos + robot[i].range) -
                        segs[j].begin();
      temp2--;
      ans += max(0LL, get(j, temp2) - get(j, temp1 - 1));
    }
  }
  cout << ans - n;
}