Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/ochkoz-zallar-soni

Minimum number of rooms

Medium 1000 ms 128 MB 47%
Share

There are $n$ lessons in a day: the $i$-th starts at time $s_{i}$ and ends at time $e_{i}$. Only one lesson can take place in a room at a time; if a lesson ends at time $t$, another one may start in that room at time $t$. What is the smallest number of rooms needed to hold all the lessons?

Lessons as segments on a time axis; the largest number of simultaneous lessons is highlighted

Input

The first line contains a positive integer $n$. Each of the next $n$ lines contains two integers: $s_{i}$ and $e_{i}$.

Output

One integer — the smallest number of rooms.

Note

$1 \le n \le 10^{5}$
$0 \le s_{i} \lt e_{i} \le 10^{9}$

Examples

Input #1
4
9 12
10 11
11 14
13 15
Output #1
2
Input #2
2
1 5
5 9
Output #2
1

Sign in to submit a solution

Signing up is free and takes a minute.