Under construction

Still being built. Things may change

Rescue Squad

Time limit1sMemory limit1024 MB

Summary
Choose a start hour s so that the window from s:30 to s+M:30 lets the most teams make two site visits, given each team's available hour intervals.
Level

Medium6 of 10

Topics
Intervals, Sliding window, Sorting
Solved
No attempts yet

Problem

Junggeuri is the captain of a school rescue squad. Upon hearing that cats are trapped in a basement, the squad decided to go rescue them. However, the squad members are students, so they can only act for MM hours, the time approved by their teacher. Once they start, they must act for MM consecutive hours without a break. Junggeuri can choose when to start. If the start time is ss (ss is a non-negative integer), Junggeuri can request activity from ss:30 to s+Ms+M:30.

The school rescue squad consists of several teams. A team's rescue work proceeds as follows.

  • The team arrives at the site and assesses the situation.
  • The team returns, analyzes the situation, and gathers the necessary supplies.
  • The team goes back to the site and completes the rescue.

Each team has a unique number cc and at least one available time interval. An interval is written [l,r)[l, r), meaning the team can be active from ll:00 to r−1r-1:59. A team can arrive at or return from the site at any time within its available hours, but once it returns during an interval, it cannot go back to the site during that same interval. Junggeuri only lets teams that can visit the site at least twice join the rescue, and wants as many such teams as possible. Help Junggeuri pick the times so that the most teams can join.

Input

The first line contains NN, the number of available time intervals, and MM, the given time, separated by a space.

Each of the next NN lines contains three integers ll, rr, and cc, separated by spaces, where [l,r)[l, r) is one of the available intervals of team cc.

The available intervals of the same team do not overlap. Precisely, for any two intervals [li,ri)[l_i, r_i) and [lj,rj)[l_j, r_j) of the same team, li≠ljl_i \neq l_j, and if li<ljl_i < l_j, then ri<ljr_i < l_j.

Output

Print the maximum number of teams that can join the rescue on the first line.

Constraints

  • 1≤N≤2×1051 \le N \le 2 \times 10^5, 1≤M≤1061 \le M \le 10^6
  • 0≤l<r≤1060 \le l < r \le 10^6, 0≤c≤1090 \le c \le 10^9
  • All input values are integers.

Examples1

  1. Example 1

    Input
    4 10
    1 5 1
    2 5 2
    6 7 1
    11 12 2
    
    Expected output
    2