This page is still under construction.

Parts of this page are still being built. What you see may change.

The Oldest Ruins

Interview

Time limit1sMemory limit128 MB

Summary
Given up to 3000 integer points, find four that form a square of the largest area and output that area, or 0 if none exist.
Level

Medium6 of 10

Topics
Geometry, Hash map, Brute force, Math
Solved
No attempts yet

Problem

Long ago there was a settlement here where many people lived. They built structures of all shapes and sizes. Those structures are long gone, and the only clues to where they once stood are the surviving records and the pillars unearthed at the site.

The records describe a temple. Seen from above, the temple was a perfect square with a pillar at each of its four corners. Which way the temple faced is unknown, and whether there were pillars along its edges or inside it is also unknown. The archaeologists reasoned that, among the pillars found at the site, the four that form a square of the largest area must mark the temple.

Given the coordinates of the pillars, write a program that finds the square of the largest area that can be formed by four pillars and outputs that area. Note that the sides of the square are not necessarily parallel to the coordinate axes.

Input

The first line contains nn, the number of pillars found at the site.

Each of the next nn lines (from line 22 through line n+1n+1) contains the xx-coordinate and yy-coordinate of one pillar, separated by a space.

No pillar appears more than once.

nn is an integer with 1≤n≤30001 \le n \le 3000, and each pillar's xx- and yy-coordinates are integers between 00 and 50005000 inclusive.

Output

Output a single integer. If a square formed by four pillars exists, output the area of the largest such square; otherwise output 00.

Hint

In the example shown below there are 10 pillars. The four at (4,2),(5,2),(5,3),(4,3)(4, 2), (5, 2), (5, 3), (4, 3) form one square, and the four at (1,1),(4,0),(5,3),(2,4)(1, 1), (4, 0), (5, 3), (2, 4) form another. The larger square is the latter, whose area is 1010.

Examples1

  1. Example 1

    Input
    10
    9 4
    4 3
    1 1
    4 2
    2 4
    5 8
    4 0
    5 3
    0 5
    5 2
    
    Expected output
    10