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 inf = int(1e9) + 7;
const long long linf = 1ll * inf * inf;
const int N = 1000000 + 7;
const int M = 10000 + 7;
const int multipleTest = 0;
const double pi = acos(-1);
template <typename T>
void addmod(T& a, const long long& b, const int MOD = inf) {
  a = (a + b) % MOD;
  if (a < 0) a += MOD;
}
template <typename T>
void mulmod(T& a, const long long& b, const int MOD = inf) {
  if (abs(a) >= MOD) a %= MOD;
  a = (abs(b) >= MOD) ? a * (b % MOD) % MOD : a * b % MOD;
  if (a < 0) a += MOD;
}
map<int, int> mapDist;
int findLeftIndex(int x) {
  auto it = mapDist.lower_bound(x);
  if (it != mapDist.end())
    return it->second;
  else
    return mapDist.size();
}
int findRightIndex(int x) {
  auto it = mapDist.upper_bound(x);
  if (it == mapDist.begin())
    return 0;
  else
    return (--it)->second;
}
int n, k;
struct Robot {
  int x;
  int range;
  int iq;
  bool operator<(const Robot& other) const { return iq < other.iq; }
  void read() { scanf("%d%d%d", &x, &range, &iq); }
};
Robot robots[N];
class FenWickTree {
 public:
  static const int MAXN = 200000 + 7;
  int L[MAXN];
  void update(int x, int val) {
    for (int t = x; t < MAXN; t += t & -t) L[t] += val;
  }
  int get(int x) {
    int res = 0;
    for (int t = x; t > 0; t -= t & -t) {
      res += L[t];
    }
    return res;
  }
} fenwickTree;
long long calc(int u, int v, int maxIq) {
  if (u >= v) return 0;
  long long res = 0;
  vector<Robot> c_robots(robots + u, robots + v + 1);
  sort(
      c_robots.begin(), c_robots.end(),
      [](const Robot& lhs, const Robot& rhs) -> bool { return lhs.x < rhs.x; });
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      heap;
  for (int i = 0, m = c_robots.size(); i < m; ++i) {
    const int curX = c_robots[i].x;
    const int pos = mapDist[curX];
    while (!heap.empty() && heap.top().first < curX) {
      int prevPos = heap.top().second;
      fenwickTree.update(prevPos, -1);
      heap.pop();
    }
    if (c_robots[i].iq == maxIq) {
      int lhs = findLeftIndex(curX - c_robots[i].range);
      if (lhs <= pos) res += heap.size() - fenwickTree.get(lhs - 1);
    }
    heap.push({curX + c_robots[i].range, pos});
    fenwickTree.update(pos, 1);
  }
  while (!heap.empty()) {
    fenwickTree.update(heap.top().second, -1);
    heap.pop();
  }
  priority_queue<pair<int, int>> maxHeap;
  for (int m = (int)(c_robots).size(), i = m - 1; i >= 0; --i) {
    const int curX = c_robots[i].x;
    const int pos = mapDist[curX];
    while (!maxHeap.empty() && maxHeap.top().first > curX) {
      int prevPos = maxHeap.top().second;
      fenwickTree.update(prevPos, -1);
      maxHeap.pop();
    }
    if (c_robots[i].iq == maxIq) {
      int rhs = findRightIndex(curX + c_robots[i].range);
      if (rhs >= pos) res += fenwickTree.get(rhs);
    } else {
      maxHeap.push({curX - c_robots[i].range, pos});
      fenwickTree.update(pos, 1);
    }
  }
  while (!maxHeap.empty()) {
    fenwickTree.update(maxHeap.top().second, -1);
    maxHeap.pop();
  }
  return res;
}
void solve() {
  cin >> n >> k;
  for (int i = (0), _b = (n); i < _b; ++i) {
    robots[i].read();
    mapDist[robots[i].x] = 0;
  }
  int distSize = 0;
  for (auto& x : mapDist) x.second = ++distSize;
  sort(robots, robots + n);
  long long res = 0;
  map<int, long long> sum;
  int j = 0;
  for (int i = 0; i < n; ++i) {
    while (i + 1 < n && robots[i + 1].iq == robots[i].iq) ++i;
    while (j < i && robots[j].iq < robots[i].iq - k) ++j;
    int curIq = robots[i].iq;
    res += calc(j, i, curIq);
  }
  cout << res << '\n';
}
int main() {
  int Test = 1;
  if (multipleTest) cin >> Test;
  for (int i = 0; i < Test; ++i) {
    solve();
  }
}