Under construction

Still being built. Things may change

Smallest Square 1

Time limit2sMemory limit512 MB

Summary
Given N points, find the smallest axis-aligned square with integer vertices that strictly contains at least N-2 of the points, and output its area.
Level

Medium7 of 10

Topics
Geometry, Sorting, Brute force, Binary search
Solved
No attempts yet

Problem

There are NN points on the coordinate plane. Find the square of smallest area that satisfies all three conditions below.

  • All four vertices of the square have integer coordinates.
  • All four sides of the square are parallel to the coordinate axes.
  • At least N−2N-2 of the given points lie strictly inside the square. A point on the boundary does not count as being inside.

Write a program that prints the smallest area of such a square.

Input

The first line contains the number of points NN. (3≤N≤503 \le N \le 50)

Each of the next NN lines contains the coordinates xx and yy of one point, separated by a space. (−109≤x,y≤109-10^9 \le x, y \le 10^9)

No point is given more than once.

Output

Print the area of the smallest square that satisfies the conditions.

Examples3

  1. Example 1

    Input
    3
    0 0
    1 1
    2 5
    
    Expected output
    4
    
  2. Example 2

    Input
    5
    -1 -2
    -1 -1
    0 0
    2 -1
    0 -2
    
    Expected output
    9
    
  3. Example 3

    Input
    4
    1000000000 1000000000
    -1000000000 1000000000
    1000000000 -1000000000
    -1000000000 -1000000000
    
    Expected output
    4000000008000000004