delivery

Time limit: 1.2s Memory limit: 256MB Input: Output:

Mathew is the owner of a delivery company. He lives in a city where there are exactly 10910^9 houses ordered in a line. Each house has a number, and the house with number i is adjacent to houses with numbers i-1 and i+1 (if they exist). Mathew’s company has received N queries for a delivery at house HiH_i at time exactly TiT_i. There are no two queries that are at the same time and at the same house. To save money, Mathew wants to know how many delivery trucks he will need to complete all the queries. The trucks he will buy can move 1 house to the left or the right in one unit of time (they can also stay at the same house). In the beginning, the trucks can be parked in front of whichever houses the owner chooses. In addition, the time for delivery is negligible.

Mathew is a busy man and has no time for easy tasks like this one so he asks you to write a program that finds the minimum number of delivery trucks he will need.

Input

From the first line of the standard input, your program should read one integer N – the number of queries. Each of the next N lines will contain two integers TiT_i and HiH_i – the time and house the delivery should happen at.

Output

On a single line, your program should output the minimum number of delivery trucks that are needed.

Constraints

  • 1N1061 ≤ N ≤ 10^6
  • 1Ti,Hi1091 ≤ T_i, H_i ≤ 10^9
  • TiTjT_i≠T_j or HiHjH_i≠H_j for i ≠ j

Subtask 1 (25 points)

  • N103N ≤ 10^3

Subtask 2 (10 points)

  • N104N ≤ 10^4

Subtask 3 (40 points)

  • N2105N ≤ 2 \cdot 10^5

Subtask 4 (20 points)

  • N106N ≤ 10^6

Example

stdin

6
1 1
2 3
3 2
5 4
4 1
4 3

stdout

2

Explanation

The minimum number of delivery trucks we need is 2.

One way to complete all deliveries is:

First truck: (1, 1)* -> (2, 1) -> (3, 1) -> (4, 1)* -> (5, 1)

Second truck: (1, 2) -> (2, 3)* -> (3, 2)* -> (4, 3)* -> (5, 4)*

Where (t, h) represents the truck being at house h at time t, and * are times on which the truck makes a delivery.

Log in or sign up to be able to send submissions!