Under construction

Still being built. Things may change

Load Balancing

Time limit2sMemory limit512 MB

Summary
Place one vertical and one horizontal fence between the odd-coordinate cow positions to minimize the largest cow count in any of the four regions.
Level

Medium5 of 10

Topics
Sorting, Prefix sum, Brute force
Solved
No attempts yet

Problem

Farmer John's NN cows stand at distinct points (x1,y1),…,(xN,yN)(x_1, y_1), \ldots, (x_N, y_N) on his two-dimensional farm (1≤N≤100,0001 \le N \le 100{,}000, and every xix_i and yiy_i is a positive odd integer of size at most 1,000,0001{,}000{,}000). FJ wants to divide the field by building a north-south fence with equation x=ax = a. The fence is effectively infinite in length, and aa is an even integer, so the fence never passes through the position of a cow. He also builds an east-west fence with equation y=by = b, where bb is an even integer as well. The two fences cross at the point (a,b)(a, b) and together cut the field into four regions.

FJ wants to choose aa and bb so that the cows in the four regions are reasonably balanced, with no region holding too many cows. Let MM be the largest number of cows in one of the four regions. FJ wants to make MM as small as possible. Determine that smallest possible value of MM.

Input

The first line contains a single integer NN. Each of the next NN lines contains the xx and yy coordinates of one cow, separated by a space.

Output

Print the smallest value of MM that FJ can achieve by placing the two fences optimally.

Examples2

  1. Example 1

    Input
    7
    7 3
    5 5
    7 13
    3 1
    11 7
    5 3
    9 1
    
    Expected output
    2
    
  2. Example 2

    Input
    4
    1 1
    1 3
    3 1
    3 3
    
    Expected output
    1