Most profitable set of jobs

N jobs each have a start time, an end time and a profit. Choose jobs that do not overlap (a job ending at time t allows another to start at t) to make the total profit as large as possible.

Input

First line: N. Next N lines: start, end and profit.

Output

The largest total profit.

Constraints

1 ≤ N ≤ 10^5; 0 ≤ start < end ≤ 10^9; 1 ≤ profit ≤ 10^4.

Example 1

Input:
4
1 3 50
2 5 20
3 6 70
5 7 30

Output:
120

Example 2

Input:
3
1 2 10
1 2 20
2 3 5

Output:
25

Example 3

Input:
3
0 10 100
1 2 30
2 3 30

Output:
100

Hint: Sort jobs by end time. best[i] = max(best[i − 1], profit[i] + best[j]) where j is the last job ending at or before job i starts; find j by binary search on the end times.

All coding practice