Under construction

Still being built. Things may change

Microbiology Lab

Time limit2sMemory limit128 MB

Summary
Choose the minimum number of distinct integer temperature points so every microbe's interval contains at least C[i] chosen points.
Level

Hard8 of 10

Topics
Greedy, Segment tree, Intervals, Binary search
Solved
No attempts yet

Problem

A research lab wants to observe N types of microbes by growing them at several temperatures.

Microbe i can be grown only at an integer temperature from A[i] through B[i], inclusive. For the experiment to be sufficient, microbe i must be grown in at least C[i] laboratories whose temperatures are all different.

Each laboratory is kept at one fixed integer temperature, and no two laboratories have the same temperature. If a laboratory has temperature T, then any number of microbes of any types satisfying A[i] ≤ T ≤ B[i] may be grown there.

All temperatures are integers from 0 to 50,000, inclusive. Find the minimum number of laboratories needed to satisfy every condition.

Input

The first line contains N, the number of microbe types. Each of the next N lines contains A[i], B[i], and C[i] for i = 1, 2, ..., N, in that order.

Output

Print the minimum number of laboratories needed.

Constraints

  • 1 ≤ N ≤ 50,000
  • 0 ≤ A[i] ≤ B[i] ≤ 50,000
  • 1 ≤ C[i] ≤ B[i] - A[i] + 1

Hint

Laboratories at temperatures 1 and 3 are sufficient.

Examples1

  1. Example 1

    Input
    3
    1 2 1
    3 4 1
    1 4 2
    
    Expected output
    2