题目描述
Problem Description
Takahashi has decided to host a competitive programming camp. Let the time when Takahashi arrives at the venue be $0$. At time $0$, Takahashi is in the waiting room and will then start registering the participants. There are $N$ participants, and the $i$-th ($=1, 2, \ldots, N$) participant starts registration at time $s_i$ and finishes at time $t_i$.
Takahashi always stays at the registration desk during the time when any participant is registering, and always stays in the waiting room when no participant is registering. Note that multiple participants can register simultaneously. More precisely, the $i$-th ($=1, 2, \ldots, N$) participant arrives at time $s_i$ and finishes registration at time $t_i$ regardless of the registration status of other participants.
Write a program to determine how many times Takahashi moves from the waiting room to the registration desk from the time he arrives at the venue until the last participant arrives. Note that the time it takes for Takahashi to move from the registration desk to the waiting room or vice versa is negligible. However, if one participant finishes registration at time $t$ and another participant starts registration at the same time $t$, Takahashi does not return to the waiting room at time $t$.
Input Format
The input is given from the standard input in the following format:
$ N $ $ s_1 $ $ t_1 $ $ s_2 $ $ t_2 $ $ : $ $ s_N $ $ t_N $
Output Format
Output the answer in one line.
Sample Input and Output
Sample Input #1
3
2 6
4 7
8 12
Sample Output #1
2
Sample Input #2
2
3 5
5 7
Sample Output #2
1
Sample Input #3
5
8 11
6 12
2 7
17 21
12 15
Sample Output #3
2
Notes/Hints
Constraints
- $1 \le N \le 2 \times 10^5$
- $1 \le s_i$
- All given inputs are integers.
Sample Explanation 1
From time $2$ to time $7$, registration is done for the 1st and 2nd participants. There is no participant registering from time $7$ to time $8$, so Takahashi returns to the waiting room. Then, from time $8$, registration starts again for the 3rd participant.
Sample Explanation 2
Note that at time $5$, when the registration for the 1st participant ends, the registration for the 2nd participant starts immediately, so there is no time for Takahashi to return to the waiting room.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分