This page is still under construction.

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

Largest Square

Time limit10sMemory limit256 MB

Summary
Given N points on a plane, find the area of the largest square with all four vertices among the points, or 0 when no square exists.
Level

Medium6 of 10

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

Problem

Given NN points on a plane, find the area of the largest square whose four vertices are all among the given points. The sides of the square need not be parallel to the coordinate axes; tilted squares are also allowed.

Input

The first line contains the number of test cases TT.

For each test case, the first line contains the number of points NN (4≤N≤30004 \le N \le 3000). Each of the next NN lines contains the xx and yy coordinates of a point, separated by a space. All coordinates are integers between −10000-10000 and 1000010000 inclusive, and no two points share the same position.

Output

For each test case, print the area of the largest square that can be formed, one per line. If no square can be formed, print 00.

Examples1

  1. Example 1

    Input
    1
    10
    5 2
    10 2
    7 4
    2 5
    8 5
    5 7
    6 7
    10 7
    8 9
    3 10
    
    Expected output
    26