#CT00045. Lịch ôn tập (Study Schedule)

Lịch ôn tập (Study Schedule)

Study Schedule

Version: Phuoc Hung OJ Extended

Problem Statement

During one day, the team computer room has NN usage proposals. Proposal ii occupies the room continuously from time SiS_i to time TiT_i and gives value ViV_i if selected.

Only one proposal can use the room at a time, so selected proposals must not overlap. If one proposal ends exactly when another begins, both may be selected.

Choose a set of proposals with maximum total value.

Input

  • The first line contains the positive integer NN.
  • The next NN lines contain three integers Si,Ti,ViS_i,T_i,V_i.

For every ii: 0≤Si<Ti≤1090 \le S_i < T_i \le 10^9 and 1≤Vi≤1091 \le V_i \le 10^9.

Output

Print one integer: the maximum total value obtainable.

Subtasks

  • Subtask 1 (30%): 1≤N≤201 \le N \le 20.
  • Subtask 2 (30%): 1≤N≤20001 \le N \le 2000.
  • Subtask 3 (40%): 1≤N≤2⋅1051 \le N \le 2\cdot 10^5.

Examples

Example 1

Input

5
1 3 5
2 5 6
4 6 5
6 7 4
5 8 11

Output

17

Explanation

Choose [2,5][2,5] with value 66 and [5,8][5,8] with value 1111. They only touch at time 55, so they are compatible, giving total 1717.

Example 2

Input

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

Output

13

Explanation

Choose [1,4][1,4] with value 1010 and [4,6][4,6] with value 33, for a total of 1313.

Example 3

Input

3
1 10 7
2 3 4
3 4 4

Output

8

Explanation

Intervals [2,3][2,3] and [3,4][3,4] are compatible and give total 88, which is better than taking only [1,10][1,10] with value 77.