#P10742. Minimizing the Area of an Orthogonal Polygon Chain

    ID: 12777 Type: Default 1000ms 256MiB

Minimizing the Area of an Orthogonal Polygon Chain

Minimizing the Area of an Orthogonal Polygon Chain

Gary has created a polygon with (n) vertices, where each vertex has coordinates ((x,y)). Your task is to connect these points with edges so that all points are included. The resulting graph must form a polygon chain, meaning it is connected and every vertex is incident to at most two edges. Moreover, if an edge is drawn between any two connected vertices (i) and (j), then that edge must be either horizontal or vertical (i.e. the two points share the same (x) or the same (y) coordinate). Among all possible polygon chains, output the minimum area of the closed polygon formed by the chain (computed using the standard shoelace formula). If no valid chain exists, output (-1).

inputFormat

The first line contains an integer (n) (1 \le n \le 10), representing the number of vertices. Each of the next (n) lines contains two integers (x) and (y) (\left(-10^9 \le x,y \le 10^9\right)), the coordinates of a vertex.

outputFormat

Output a single integer, the minimum area (in square units) of the polygon chain. If no valid polygon chain exists, output (-1).

sample

4
0 0
0 1
1 1
1 0
1