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 ll = long long;
const int MN = 1e5 + 10;
int N, K, Q, iq[MN], loc[MN], rm[MN];
bool cmp(int x, int y) { return rm[x] > rm[y]; }
std::priority_queue<int, std::vector<int>, std::function<bool(int, int)> > q(
    cmp);
ll ans;
struct robot {
 public:
  int x, r, q;
  void in() { scanf("%d%d%d", &x, &r, &q); }
  bool operator<(robot o) const { return x < o.x; }
};
robot a[MN];
struct BIT {
 public:
  std::vector<int> a;
  std::vector<int> x;
  int S, L, tot;
  void build() {
    S = x.size();
    a.assign(S, 0);
    L = 31 - __builtin_clz(S);
  }
  void upd(int n, int v) {
    tot += v;
    for (++n; n <= S; n += -n & n) a[n - 1] += v;
  }
  int get(int n) {
    int i = 0, j = L, f = 0;
    for (; j >= 0; --j)
      if ((i | 1 << j) <= S && x[(i | 1 << j) - 1] < n)
        f += a[(i |= 1 << j) - 1];
    return tot - f;
  }
};
BIT bit[MN];
int main(void) {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; ++i) a[i].in(), iq[i] = a[i].q;
  std::sort(a, a + N);
  std::sort(iq, iq + N);
  Q = std::unique(iq, iq + N) - iq;
  for (int i = 0; i < N; ++i) {
    int q = a[i].q = std::lower_bound(iq, iq + Q, a[i].q) - iq;
    if (bit[q].x.empty() || bit[q].x.back() != a[i].x)
      bit[q].x.push_back(a[i].x);
    loc[i] = bit[q].x.size() - 1;
  }
  for (int i = 0; i < Q; ++i) bit[i].build();
  for (int i = 0; i < N; ++i) {
    while (!q.empty() && rm[q.top()] < a[i].x) {
      int x = q.top();
      q.pop();
      bit[a[x].q].upd(loc[x], -1);
    }
    int miq = iq[a[i].q];
    for (int j = a[i].q; j < Q && miq + K >= iq[j]; ++j)
      ans += bit[j].get(a[i].x - a[i].r);
    for (int j = a[i].q - 1; j >= 0 && iq[j] + K >= miq; --j)
      ans += bit[j].get(a[i].x - a[i].r);
    bit[a[i].q].upd(loc[i], 1);
    rm[i] = a[i].x + a[i].r;
    q.push(i);
  }
  printf("%lld\n", ans);
  return 0;
}