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

~/algor $ cat problems/saralash-kerakli-xonalar

Rooms needed

Medium 1000 ms 128 MB 66%
Share

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

Lessons as segments on a time axis; the place of the largest simultaneous overlap 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 number of rooms.

Note

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

Examples

Input #1
4
1 5
2 4
5 7
4 6
Output #1
2
Input #2
1
0 1
Output #2
1

Sign in to submit a solution

Signing up is free and takes a minute.