PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000115. Lịch học liên cơ sở (NTNU Orienteering)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Lịch học liên cơ sở (NTNU Orienteering)

NTNU Orienteering

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

There are CC campuses and LL lectures. Lecture ii takes place at campus cic_i from absolute time sis_i through eie_i (microseconds); it counts only when attended in its entirety. Every pair of campuses has a direct two-way bus travel time; transfers can shorten journeys. You may start early at any campus and depart as soon as a lecture ends. Maximize the number of lectures attended from start to finish.

Input

First line CC, second line LL; next exactly C(C−1)/2C(C-1)/2 rows u,v,tu,v,t (every campus pair exactly once); then LL rows c,s,ec,s,e. Campuses are indexed from 00.

Output

Print the maximum number of lectures.

Subtasks

  • Subtask 1 (40 points): 1≤C≤41\le C\le 4, 1≤L≤81\le L\le 8, 1≤t≤1001\le t\le 100, 0≤s<e≤10000\le s<e\le 1000. All input conditions remain in force.

  • Subtask 2 (60 points): 1≤C≤2001\le C\le 200, 1≤L≤10001\le L\le 1000, 1≤t≤8 600 0001\le t\le 8\,600\,000, 0≤s<e≤8 600 0000\le s<e\le 8\,600\,000. All input conditions remain in force.

Examples

Input

3
2
0 1 5
1 2 5
0 2 100
0 0 90
2 100 110

Output

2

Explanation

The shortest trip from campus 0 to campus 2 takes 10 through campus 1. After a lecture ending at 90 you reach campus 2 by 100; both lectures are attended.