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

#PS0000250. Điểm số cao nhất (High Score)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Điểm số cao nhất (High Score)

High Score

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Takahashi plays a game with NN ruins and MM gem types numbered from 1 to MM. He may explore ruins in any order, at most once per ruin. Exploring ruin ii awards sis_i points and one gem of every type in the inclusive interval [li,ri][l_i,r_i]. Gems cannot be discarded. Acquiring all MM types revives the demon king and cancels the score of the ruin being explored. Takahashi wants to choose ruins so that the demon king never revives and his total score is maximized. Exploring no ruins is allowed. Find the maximum score.

Input

First line: integers N,MN,M. Each of the next NN lines contains three integers li,ri,sil_i,r_i,s_i.

Output

Print one integer: the maximum score without reviving the demon king.

Subtasks

  • Subtask 1 (30 points): 1≤N,M≤81\le N,M\le 8; 1≤li≤ri≤M1\le l_i\le r_i\le M; 1≤si≤50001\le s_i\le5000.
  • Subtask 2 (69 points): 1≤N,M≤50001\le N,M\le 5000; 1≤li≤ri≤M1\le l_i\le r_i\le M; 1≤si≤50001\le s_i\le5000.
  • Subtask 3 (1 points): 1≤N,M≤1000001\le N,M\le 100000; 1≤li≤ri≤M1\le l_i\le r_i\le M; 1≤si≤50001\le s_i\le5000.

Example 1

Input

4 6
1 3 30
2 3 40
3 6 25
6 6 10

Output

80

Explanation

Choose ruins 1, 2 and 4 for 80 points, leaving types 4 and 5 missing. No choice leaving a type missing exceeds 80.

Example 2

Input

2 7
1 3 90
5 7 90

Output

180

Explanation

Explore both ruins, leaving type 4 missing and earning 180 points.

Example 3

Input

1 4
1 4 70

Output

0

Explanation

The only ruin contains all four types, so it cannot be explored.