// Arup Guha
// 3/29/2025
// Solution to Kattis Problem: Distributed Seats
/*** Note: Since Python doesn't have sorted sets, I don't know how to convert this to
           python without writing a treemap in Python from scratch.
***/

import java.util.*;
import java.io.*;

public class distributedseats {

	public static void main(String[] args) throws Exception {

		// Get basic information.
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer toks = new StringTokenizer(stdin.readLine());
		int n = Integer.parseInt(toks.nextToken());
		person.r = Integer.parseInt(toks.nextToken());
		int c = Integer.parseInt(toks.nextToken());
		
		// Store people here.
		person[] list = new person[n];
		for (int i=0; i<n; i++) {
			toks = new StringTokenizer(stdin.readLine());
			int myr = Integer.parseInt(toks.nextToken()) - 1;
			int myc = Integer.parseInt(toks.nextToken());
			int diff = Integer.parseInt(toks.nextToken());
			list[i] = new person(myr, diff);
		}
		
		// Sorts by "end time" (last row you can sit in), breaking ties by
		// reverse "start time" (first row you can sit in).
		Arrays.sort(list);
		
		// map[i] stores how many seats are available in row i. Initially all are.
		TreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>();
		for (int i=0; i<person.r; i++)
			map.put(i, c);
		
		int res = 0;
		
		// Loop through people, placing them one at a time.
		// We process by priority...the earlier you have to sit (lower max row), the
		// earlier we try to seat you.
		for (int i=0; i<n; i++) {
			
			// Get lowest row this person could possible sit.
			Integer nextKey = map.higherKey(list[i].start-1);
			
			// No where to sit.
			if (nextKey == null) continue;
			
			// You can't sit in the first available seat.
			if (nextKey > list[i].end) continue;
			
			// Sit down on the first valid seat (minimum row) that is available.
			int left = map.get(nextKey);
			if (left > 1)
				map.put(nextKey, left-1);
			
			// Here you took the last seat on the row, so we remove this row from possibility.
			else
				map.remove(nextKey);
			
			// One more person seated.
			res++;
		}
		
		// Ta da!
		System.out.println(res);
	}
}

// Just to help us custom sort.
class person implements Comparable<person> {

	public static int r;
	
	public int start;
	public int end;
	
	public person(int myr, int myd) {
		start = Math.max(0, myr-myd);
		end = Math.min(r-1, myr+myd);
	}
	
	// Sort by end time in increasing order, breaking ties by start time in decreasing order.
	public int compareTo(person other) {
		if (this.end != other.end)
			return this.end - other.end;
		return other.start - this.start;
	}
}