Under construction

Still being built. Things may change

Convex Polygon MST

Time limit7sMemory limit1024 MB

Summary
Given a convex polygon's vertices, find the spanning tree whose edges, weighted by squared Euclidean length, have the maximum total weight.
Level

Hard8 of 10

Topics
Graph, Minimum spanning tree, Geometry
Solved
No attempts yet

Problem

There is a convex polygon with nn vertices on a plane. Let VV be the set of its vertices. Remove all the edges of the polygon, and then create a tree with nn vertices by repeating the following operation n−1n-1 times:

  • Select two distinct vertices x,y∈Vx, y \in V. Add an edge between xx and yy. If the Euclidean distance between xx and yy is d(x,y)d(x,y), you gain (d(x,y))2(d(x,y))^2 points.

Find the maximum possible total score from the n−1n-1 operations.

Input

The input file contains multiple test cases. The first line contains an integer tt, the number of test cases. Then tt test cases follow, each in the following format.

nn

x1x_1 y1y_1 ⋮ xnx_n yny_n

nn is the number of vertices, with 3≤n≤120 0003 \le n \le 120\,000. The sum of all nn values in one input file is at most 120 000120\,000. xix_i and yiy_i are the coordinates of the ii-th vertex, and each coordinate is an integer from −109-10^9 to 10910^9. The vertices are given in counterclockwise order as seen from the centroid of the convex polygon. No three distinct vertices of the convex polygon lie on a single line.

Output

Print the maximum possible total score from the n−1n-1 operations.

Hints

The Euclidean distance between (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is ∣x1−x2∣2+∣y1−y2∣2\sqrt{|x_1 - x_2|^2 + |y_1 - y_2|^2}.

The answer can exceed 2642^{64}.

Examples1

  1. Example 1

    Input
    2
    4
    0 0
    1 0
    1 1
    0 1
    6
    986288255 165031740
    -353860917 -935298054
    -173584601 -984818960
    141060317 -990001002
    341839727 -939758266
    662792114 -748803453
    
    Expected output
    5
    10426936519662708146