#P1868. 饥饿的奶牛

饥饿的奶牛

Description

A cow broke through the fence and reached a sanctuary (for cows), where a message was written in the cow language.

Translated, it says:

There are NN intervals. Each interval x,yx,y provides xyx \sim y, a total of yx+1y-x+1 piles of premium pasture. You may choose any intervals, but they must not overlap.

For the cow, the more it eats, the better. However, the cow is not very smart, so please help it.

Input Format

The first line contains an integer NN.

The next NN lines each contain two numbers x,yx,y, describing an interval.

Output Format

Output the maximum number of pasture piles the cow can eat.

3
1 3
7 8
3 4
5

Hint

1n1.5×1051 \leq n \leq 1.5 \times 10^50xy3×1060 \leq x \leq y \leq 3 \times 10^6

Translated by ChatGPT 5