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

#BF0000032. Chọn số nguyên theo các đoạn (Intervals)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chọn số nguyên theo các đoạn (Intervals)

Intervals

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn closed integer intervals [ai,bi][a_i,b_i], choose a set of distinct integers ZZ containing at least cic_i chosen integers in each interval. Minimize ∣Z∣|Z|.

Only distinct integers are selected; selecting the same integer twice does not help.

This Extended version omits the original count of independent test cases.

Input

First line nn. Then nn lines ai,bi,cia_i,b_i,c_i.

Output

Print the minimum number of selected integers.

Subtasks

  • Subtask 1 (20 points): $1\le n\le20; 0\le a_i\le b_i\le30; 1\le c_i\le b_i-a_i+1$.
  • Subtask 2 (30 points): $1\le n\le2500; 0\le a_i\le b_i\le3000; 1\le c_i\le b_i-a_i+1$.
  • Subtask 3 (50 points): $1\le n\le50000; 0\le a_i\le b_i\le50000; 1\le c_i\le b_i-a_i+1$.

Examples

Input

3
1 3 2
2 5 2
4 5 1

Output

3

Explanation

The selected integers {2,3,5}\{2,3,5\} cover the three intervals with respectively 22, 33, and 11 points. At least three points are needed, as the first and last intervals need disjoint selected points except where they do not overlap.