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 long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const double eps = (double)1e-9;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 100500;
int n, k, xi[N], ma[3 * N], l[N], r[N], m, q[N], t[2][3 * N], p[N], rad[N];
long long ans;
bool cmp(int x, int y) { return q[x] < q[y]; }
bool cmp1(int x, int y) { return rad[x] > rad[y]; }
void upd(int num, int i, int x) {
  for (; i <= m; i |= (i + 1)) t[num][i] += x;
}
int get(int num, int i) {
  int result = 0;
  for (; i >= 0; i = (i & (i + 1)) - 1) result += t[num][i];
  return result;
}
int get(int num, int L, int R) { return get(num, R) - get(num, L - 1); }
int zna(int x) {
  int L = 1, R = m;
  while (L <= R) {
    int md = (L + R) >> 1;
    if (ma[md] <= x)
      L = md + 1;
    else
      R = md - 1;
  }
  return L - 1;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    int ra;
    scanf("%d%d%d", &xi[i], &ra, &q[i]);
    rad[i] = ra;
    l[i] = xi[i] - ra - 1;
    r[i] = xi[i] + ra;
    ma[++m] = xi[i];
    ma[++m] = l[i];
    ma[++m] = r[i];
    p[i] = i;
  }
  sort(ma + 1, ma + m + 1);
  m = unique(ma + 1, ma + m + 1) - ma - 1;
  for (int i = 1; i <= n; ++i) {
    xi[i] = zna(xi[i]);
    l[i] = zna(l[i]);
    r[i] = zna(r[i]);
  }
  sort(p + 1, p + n + 1, &cmp);
  for (int i = 1; i <= n; ++i) {
    int ra = i;
    while (ra + 1 <= n && q[p[ra + 1]] <= k + q[p[i]]) ra++;
    vector<int> v;
    for (int j = i; j <= ra; ++j) v.push_back(p[j]);
    sort(v.begin(), v.end(), &cmp1);
    for (auto j : v) {
      if (q[j] == q[p[i]]) {
        ans += get(1, l[j] + 1, r[j]) + get(0, l[j] + 1, r[j]);
        upd(0, xi[j], 1);
      } else {
        ans += get(0, l[j] + 1, r[j]);
        upd(1, xi[j], 1);
      }
    }
    for (auto j : v) {
      if (q[j] == q[p[i]])
        upd(0, xi[j], -1);
      else
        upd(1, xi[j], -1);
    }
    while (i + 1 <= n && q[p[i + 1]] == q[p[i]]) i++;
  }
  printf("%I64d", ans);
  return 0;
}