Under construction

Still being built. Things may change

Square Stamping

Time limit1sMemory limit2048 MB

Summary
Given n points lying on the lines y = -9999, 0, and 9999, find the fewest axis-parallel squares of side 10000 that cover all of them.
Level

Medium6 of 10

Topics
Greedy, Dynamic programming, Sorting
Solved
No attempts yet

Problem

In the plane, there are nn points whose yy-coordinates are each one of −9999-9999, 00, or 99999999. Let PP be the set of these nn points. Your task is to enclose all points in PP with a minimum number of congruent axis-parallel squares of side length 1000010000. Each square is a closed region, so it contains all points inside it and on its boundary.

Input

The first line contains an integer nn (1≤n≤3000001 \le n \le 300000), the number of points in PP. Each of the following nn lines contains two integers xx and yy, the coordinates of a point. Here −109≤x≤109-10^9 \le x \le 10^9 and y∈{−9999,0,9999}y \in \{-9999, 0, 9999\}. All input points are distinct.

Output

Print one line containing the minimum number tt such that tt axis-parallel squares of side length 1000010000 have a union that encloses all points in PP.

Examples3

  1. Example 1

    Input
    5
    0 9999
    0 0
    0 -9999
    200 0
    10000 9999
    
    Expected output
    2
    
  2. Example 2

    Input
    5
    10 -9999
    0 0
    3 9999
    9000 -9999
    10003 9999
    
    Expected output
    2
    
  3. Example 3

    Input
    6
    10 -9999
    0 0
    3 9999
    9000 -9999
    10003 -9999
    10003 9999
    
    Expected output
    3