Squeeze the Cylinders

Given up to 500 ground-resting cylinders with fixed order, compute the minimum wall-to-wall width when squeezed together.

Medium6Dynamic programmingGeometryNo attempts yetTime limit1sMemory limit256 MB

Problem

Several heavy metal cylinders lie on the flat ground of a stockyard. They all have the same length, and their diameters may differ. Their ends are aligned and their axes point in exactly the same direction.

You want to shrink the area they occupy. The cylinders are far too heavy to lift, but rolling them is not hard, so you push them together with two tall walls, one from each side.

Compute the smallest possible distance between the two walls once the cylinders are squeezed as much as possible. Cylinders may touch each other and they may touch the walls. No cylinder can be lifted off the ground, so their order never changes.

Figure B.1. Cylinders between two walls

Input

The input consists of a single test case.

The first line has an integer NN (1N5001 \le N \le 500), the number of cylinders.

The second line has the NN radii of the cylinders, listed in order from one side to the other. Every radius is an integer between 11 and 1000010000.

Output

Print the distance between the two walls after they fully squeeze the cylinders, on one line.

Round the value to six digits after the decimal point and print all six of them, even when the value is an integer. For example, print 40.000000 for a distance of 4040.

Note

The three figures below correspond to the first, the second and the third example, in that order.

Figure B.2. First exampleFigure B.3. Second exampleFigure B.4. Third example