Balancing Line

Find the shortest closed curve avoiding square lamp footprints that encloses a nonempty lamp group holding half the total energy.

Hard9GeometryBrute forceShortest pathNo attempts yetTime limit10sMemory limit256 MB

Problem

A well designed room is well lit. Following the teachings of feng shui, you placed lamps around a newly designed room to give it a friendlier air. Some lamps give off positive energy and the rest give off negative energy. The guru next door keeps that energy in balance for you, for a small fee.

A balancing line is one continuous closed curve drawn on the floor. It splits the lamps into an inside group and an outside group, the two groups have the same total energy, and at least one lamp lies inside.

A lamp takes up floor space, so the line cannot cut through it. The lamp at (x,y)(x, y) occupies the open square (x1,x+1)×(y1,y+1)(x-1, x+1) \times (y-1, y+1). The line may run along the boundary of that square, but it never enters the inside of the square. When the squares of two lamps meet along an edge or at a corner, a tiny gap is still left between the real footprints, so the line slips through.

The line may touch or overlap itself. To decide where a lamp sits, draw a ray from its centre that does not run along any part of the line. The lamp is inside when the ray crosses the line an odd number of times, and outside when it crosses an even number of times.

Find the length of the shortest balancing line.

Input

The first line has one integer NN (2N122 \le N \le 12), the number of lamps.

Each of the next NN lines has three integers xix_i, yiy_i and eie_i (1xi,yi991 \le x_i, y_i \le 99, 2000ei2000-2000 \le e_i \le 2000), separated by spaces. The pair (xi,yi)(x_i, y_i) is the position of the ii-th lamp in centimetres from the corner of the room, and eie_i is the energy that lamp contributes.

No two footprints overlap: for any two different lamps ii and jj, xixj2|x_i - x_j| \ge 2 or yiyj2|y_i - y_j| \ge 2.

Output

Print the length of the shortest balancing line, rounded to exactly six digits after the decimal point. If no balancing line exists, print IMPOSSIBLE instead.