#Q89. 「一本通 3.4 例 1」Intervals

「一本通 3.4 例 1」Intervals

Description

Original source: Southwestern Europe 2002, problem statement can be found at POJ 1201.

Given nn closed intervals [ai,bi][a_i, b_i] and nn integers cic_i, you need to construct an integer set ZZ such that for any i[1,n]i\in [1,n], the number of integers xx in ZZ that satisfy aixbia_i\le x\le b_i is at least cic_i. Find the minimum number of integers that such a set ZZ must contain.

In simpler terms, select as few integers as possible from the range 05×1040\sim 5\times 10^4 such that each interval [ai,bi][a_i, b_i] contains at least cic_i selected integers.

Input Format

The first line contains an integer nn, representing the number of intervals.

The following nn lines describe the intervals. The (i+1)(i+1)-th line contains three integers ai,bi,cia_i, b_i, c_i, separated by spaces.

Output Format

A single line outputting the minimum number of integers required to meet the conditions.

Sample 1

5
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1

6

Data Range and Hints

For all data, 1n5×1041\le n\le 5\times 10^4, 0aibi5×1040\le a_i\le b_i\le 5\times 10^4, and 1cibiai+11\le c_i\le b_i-a_i+1.