#P3028. Maximize the Number of Worshipers

    ID: 16286 Type: Default 1000ms 256MiB

Maximize the Number of Worshipers

Maximize the Number of Worshipers

There are N people who wish to worship the great JZ. However, JZ does not know where to appear and, as he cannot be in two places at once, he must pick a single integer point where he will make his appearance. Each person has a fixed activity range, so if JZ appears at any integer point within a person's range, that person will be able to worship him.

You are given N intervals, where the ith interval is denoted as \([A_i, B_i]\) with the conditions \[ 1 \le A_i \le B_i \le 1{,}000{,}000{,}000, \] and the number of people satisfies \[ 1 \le N \le 50{,}000. \]

Your task is to determine the maximum number of people who can worship JZ if he chooses the optimal location to appear.


Explanation:

For example, consider 4 intervals corresponding to 4 people: [3, 5], [4, 8], [1, 2], and [5, 10]. Note that persons with ranges [3, 5], [4, 8], and [5, 10] can all be satisfied if JZ chooses to appear at point 5, while the person with the range [1, 2] cannot. Thus, the maximum number of worshipers is 3.

inputFormat

The first line contains a single integer N, the number of people.

Each of the following N lines contains two integers Ai and Bi, representing the start and end of the activity range for the ith person.

It is guaranteed that \(1 \leq A_i \leq B_i \leq 1{,}000{,}000{,}000\).

outputFormat

Output a single integer representing the maximum number of people that can worship JZ by choosing an optimal appearance point.

sample

4
3 5
4 8
1 2
5 10
3

</p>