P1868 Hungry Cow

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 $N$ intervals. Each interval $x,y$ provides $x \sim y$, a total of $y-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 $N$. The next $N$ lines each contain two numbers $x,y$, describing an interval.

Output Format

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

Explanation/Hint

$1 \leq n \leq 1.5 \times 10^5$,$0 \leq x \leq y \leq 3 \times 10^6$。 Translated by ChatGPT 5