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

#GD0000238. Nhận dạng thuật toán: Chọn công việc có thưởng (Mixed Greedy Recognition 01)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Nhận dạng thuật toán: Chọn công việc có thưởng (Mixed Greedy Recognition 01)

Mixed Greedy Recognition 01

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn jobs. Job ii starts at sis_i, ends at eie_i, and pays reward viv_i. One worker may perform only one job at a time. Two jobs are compatible if the earlier one ends no later than the later one's start.

Choose a non-overlapping subset maximizing total reward. You may select no jobs. This exercise contrasts maximum job count with maximum weighted reward.

Input

  • The first line contains nn.
  • Each of the next nn lines contains si,ei,vis_i,e_i,v_i.

Output

Print the maximum achievable total reward.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 0≤si<ei≤1090\le s_i<e_i\le 10^9; 1≤vi≤1091\le v_i\le 10^9.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 0≤si<ei≤1090\le s_i<e_i\le 10^9; 1≤vi≤1091\le v_i\le 10^9.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 0≤si<ei≤1090\le s_i<e_i\le 10^9; 1≤vi≤1091\le v_i\le 10^9.

Examples

Input

4
1 3 5
3 4 6
1 4 10
4 5 3

Output

14

Explanation

Choose jobs (1,3,5)(1,3,5), (3,4,6)(3,4,6), and (4,5,3)(4,5,3), which do not overlap because an end may equal the next start. Their reward totals 5+6+3=145+6+3=14. Taking (1,4,10)(1,4,10) and (4,5,3)(4,5,3) gives only 1313. The answer is 1414.