QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 1024 MB Points totaux : 100

#14754. Cat-pillar plays CF

Statistiques

Maomaochong likes to participate in CF, but it is very picky; it only likes to participate in contests where the difficulty is not lower than its current ability value.

Formally, let Maomaochong's ability value be $x$ (initially $x = 0$). There are $n$ contests, where the $i$-th contest has a difficulty $a_i$ and a hidden score $b_i$. Maomaochong will participate in the $i$-th contest if and only if its current ability value $x \le a_i$. After participating, its ability value will be updated to $\max(b_i, x)$.

You can arrange the order of the contests arbitrarily. What is the maximum number of contests Maomaochong can participate in?

Input

The first line contains an integer $n$ ($1 \le n \le 10^6$).

The next $n$ lines each contain two integers $a_i, b_i$ ($0 \le a_i, b_i \le 10^{18}$), representing the difficulty and hidden score of the $i$-th contest, respectively.

Output

An integer representing the maximum number of contests Maomaochong can participate in.

Examples

Input 1

10
19 18
6 15
5 8
4 20
18 3
16 9
0 7
5 17
2 13
15 17

Output 1

5

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.