IntermediateAlgorithms25 points

How many loading docks does the warehouse need?

A logistics hub near Rotterdam receives trucks that each occupy a loading dock for a known time window. A truck occupies a dock during the half-open interval [start, end) in minutes after midnight, so a truck that arrives exactly when another one leaves can reuse the same dock. The manager wants to build the minimum number of docks so that no truck ever has to wait.

Task: the first line holds n (1 to 200). Each of the next n lines holds start end with 0 ≤ start < end ≤ 2000. Print the minimum number of docks needed.

Sample test

Input

5
0 30
5 10
15 20
10 15
25 40

Expected output

2

Your answer is also checked against 4 hidden tests.

Need a hint?

Process trucks by start time and keep track of when each busy dock becomes free.