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 JAVA):

Solution:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;


public class G {

	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;
	static class Sort implements Comparable<Sort> {
		int x, r, q;
		@Override
		public int compareTo(Sort o) {
			return this.x-o.x;
		}
	}
	static class QueElems implements Comparable<QueElems> {
		int id;
		int toX;
		@Override
		public int compareTo(QueElems o) {
			return this.toX-o.toX;
		}
		public QueElems(int id, int toX) {
			this.id = id;
			this.toX = toX;
		}
	}
	static int[][]tree;
	
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int n = nextInt();
		int k = nextInt();
		Sort[]a = new Sort[n];
		Integer[] iq = new Integer[n];
		for (int i = 0; i < n; i++) {
			a[i] = new Sort();
			a[i].x = nextInt();
			a[i].r = nextInt();
			a[i].q = nextInt();
			iq[i] = a[i].q;
		}
		Arrays.sort(iq);
		Map<Integer, Integer> map = new TreeMap<>();
		map.put(iq[0], 0);
		int maxIq = 0;
		int[]iqRealVal = new int[n];
		iqRealVal[0] = iq[0];
		for (int i = 1; i < n; i++) {
			if (!iq[i].equals(iq[i-1])) {
				maxIq++;
			}
			map.put(iq[i], maxIq);
			iqRealVal[maxIq] = iq[i];
		}
		for (int i = 0; i < n; i++) {
			a[i].q = map.get(a[i].q);
		}
		Arrays.sort(a);
		long ans = 0;
		int[]minSeeId = new int[n];
		for (int i = 0; i < n; i++) {
			int left = -1, right = i;
			while (right-left > 1) {
				int mid = (left + right) >> 1;
				if (a[i].x-a[i].r <= a[mid].x) {
					right = mid;
				}
				else {
					left = mid;
				}
			}
			minSeeId[i] = right;
		}
		PriorityQueue<QueElems> []queue = new PriorityQueue[n];
		map.clear();
		for (int i = 0; i < n; i++) {
			queue[i] = new PriorityQueue<QueElems>();
			if (!map.containsKey(a[i].q)) {
				map.put(a[i].q, 1);
			} else {
				map.put(a[i].q, map.get(a[i].q)+1);
			}
		}
		tree = new int[n][];
		ArrayList<Integer>[] vals = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			if (map.containsKey(i)) {
				tree[i] = new int[map.get(i) + 1];
			}
			vals[i] = new ArrayList<Integer>();
		}
		for (int i = 0; i < n; i++) {
			vals[a[i].q].add(i);
		}
		Map<Integer, Integer>[]mapVal = new TreeMap[n];
		
		for (int i = 0; i < n; i++) {
			Collections.sort(vals[i]);
			mapVal[i] = new TreeMap<>(); 
			if (!vals[i].isEmpty()) {
				mapVal[i].put(vals[i].get(0), 1);
				int last = 1;
				for (int j = 1; j < vals[i].size(); j++) {
					if (!vals[i].get(j).equals(vals[i].get(j-1))) {
						last++;
					}
					mapVal[i].put(vals[i].get(j), last);
				}
			}
		}
		for (int i = 0; i < n; i++) {
			int min = Math.max(0, a[i].q-k);
			int max = Math.min(n-1, a[i].q+k);
			for (int j = min; j <= max; j++) {
				if (Math.abs(iqRealVal[j]-iqRealVal[a[i].q]) > k || vals[j].isEmpty()) {
					continue;
				}
				while (!queue[j].isEmpty() && queue[j].peek().toX < a[i].x) {
					inc(j, mapVal[j].get(queue[j].peek().id), -1);
					queue[j].poll();
				}
				int y = Collections.binarySearch(vals[j], minSeeId[i]);
				if (y < 0)
					y = Math.abs(y)-1;
				if (y < vals[j].size())
					ans += sum(j, tree[j].length-1)-sum(j, mapVal[j].get(vals[j].get(y))-1);
			}
			queue[a[i].q].add(new QueElems(i, a[i].x + a[i].r));
			inc(a[i].q, mapVal[a[i].q].get(i), 1);
		}
		System.out.println(ans);
		pw.close();
	}
	private static long sum(int i, int id) {
		int res = 0;
		for (int j = id; j >= 1; j = (j & (j-1))) {
			res += tree[i][j];
		}
		return res;
	}
	private static void inc(int i, int id, int delta) {
		for (int j = id; j < tree[i].length; j = (j | (j-1)) + 1) {
			tree[i][j] += delta;
		}
	}
	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	private static String next() throws IOException {
		while (st==null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}