QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 10

#10640. Banjo [B]

Statistics

One day, Bytazar went to the market in Bytograd to play the banjo. To avoid bothering the local residents too much, he decided to play only two short, one-minute songs. Despite this, Bytazar really wanted as many people as possible to hear him. So, he played one song, waited a while, and then played the second one. Now he wonders if more people could have heard his performance.

During the day, $n$ people passed through the market, whom we will number from 1 to $n$. Bytazar remembered exactly who came to the market and when. Person number $i$ appeared at the market exactly at the beginning of the $p_{i}$-th minute (counting from dawn) and left the market at the beginning of the $k_{i}$-th minute.

Bytazar would like to calculate the maximum number of people who could hear his playing if he started his performances at optimal times. However, this problem exceeded his calculation skills, as a day in Byteland lasts $10^{9}$ minutes. Desperate, Bytazar asked you for help.

We assume that Bytazar plays exactly twice, for one minute each time. Each performance can start at any time. In particular, the second song can start immediately after the first one ends. A person hears a performance if they are at the market during the entire minute that Bytazar is playing.

Input

The first line of input contains a single integer $n$ ($1 \le n \le 500\,000$) representing the number of people who came to the market during the day. Each of the next $n$ lines describes one person. The $i$-th of these lines contains two integers $p_{i}$ and $k_{i}$ ($1 \le p_{i} \le k_{i} \le 10^{9}$), which mean that person number $i$ came to the market at the beginning of minute $p_{i}$ and left at the beginning of minute $k_{i}$.

Output

Your program should output the maximum number of different people who can hear Bytazar's banjo performances.

Examples

Input 1

7
3 6
1 16
9 13
4 6
7 9
1 1
9 10

Output 1

5

Note

Bytazar starts the first song at any time during the fourth minute or at the beginning of the fifth minute. Thus, the first song is heard by people 1, 2, and 4. Bytazar plays the second song in the ninth minute, when people 2, 3, and 7 are at the market. In total, 5 different people hear Bytazar.

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.