Under construction

Still being built. Things may change

Invigilation

Time limit1sMemory limit512 MB

Summary
Given a polyline wall with towers, find the fewest cameras on the line y = H so that every tower is visible from at least one camera.
Level

Medium7 of 10

Topics
Geometry, Greedy, Intervals
Solved
No attempts yet

Problem

The Smurfs have built the Great Smurfy Wall. The wall is a sequence of points connected by straight wall segments. The Smurfs have also built towers on some of those points. Gargamel needs to observe all of those towers, but he cannot do it himself because wall segments can block his view. It is possible to see all towers from along the wall. He wants to place some cameras along a highway that runs near the wall. Cameras are very expensive, so Gargamel asks you to find the minimal number of cameras he needs.

Input

The first line contains integers nn and HH (1≤n≤1051 \leq n \leq 10^5, 1≤H≤1061 \leq H \leq 10^6). nn is the number of points on the wall, and HH specifies that the highway is the line y=Hy = H. Each of the next nn lines describes a point of the Great Smurfy Wall with three integers xi,yi,zix_i, y_i, z_i (0≤xi≤1060 \leq x_i \leq 10^6, 0≤yi<H0 \leq y_i < H, zi∈{0,1}z_i \in \{0,1\}). (xi,yi)(x_i, y_i) are the coordinates of the point, and zi=1z_i = 1 if and only if there is a tower at that point. y1y_1 and yny_n are always 00. The points are given in strictly increasing order of xix_i.

Output

Output the minimal number of cameras Gargamel needs to use.

Examples1

  1. Example 1

    Input
    9 30
    0 0 1
    15 5 1
    25 20 1
    40 10 1
    60 5 1
    70 15 1
    82 0 1
    90 8 1
    100 0 1
    
    Expected output
    2