cswork / OAOpen practice workspace

JPMorgan ChaseOA #22

Task Scheduling

Estimated MediumJudge-ready

Topics (AI-labelled)Prefix & RangesStacks & Heaps

Each task occupies one machine during [start,end], endpoints included, and each machine runs at most one task at any moment. Find the minimum number of machines. Original example 2 contains an invalid task with start>end and its explanation re-pairs the values, so this corrupted example is not used.

Input

The first line contains n, followed by n lines of start end; full original bounds 1≤n≤200000, 1≤start≤end≤1000000000.

Output

Output a single integer answer.

Example 1

Input:

5
1 7
8 9
3 6
9 14
6 7

Output:

3

Example 2

Input:

4
2 5
2 5
2 5
2 5

Output:

4

Example 3

Input:

2
1 2
2 3

Output:

2

Example notes

The outputs of the three public examples are, in order: 3; 4; 2. These answers have been checked by independent enumeration or direct simulation.

Editorial

Loading solution…