Under construction

Still being built. Things may change

Fences Make Good Neighbors

Time limit4sMemory limit2048 MB

Summary
Triangulate a convex polygon so that exactly two fences separate the two brothers' parcels, avoiding fences through their houses, and minimize total fence length.
Level

Hard8 of 10

Topics
Dynamic programming, Geometry
Solved
No attempts yet

Problem

The King of Gletrian has a large estate that he wants to divide into triangular parcels, which he will give to deserving (that is, wealthy) followers. The estate is a convex polygon with fences already along its borders, so the only cost is the new fencing used to partition the land. Every new fence runs in a straight line between existing corners of the estate, and no two fences cross. Being fiscally minded (that is, cheap), the King wants to use as little fencing as possible.

There is a problem. He has two sons who already live on the estate. One is a cute young lad, and the other is somewhat obtuse. They do not get along. A single fence between their two parcels is out of the question, because it would lead to constant bickering and possibly a physical altercation. The King hopes his sons will learn to appreciate one another, and he believes they need one good arbiter to serve as a liaison. So he wants exactly two fences between the brothers' parcels, with a single parcel between them where he will place a conscripted volunteer to serve as go-between. He still wants to minimize the total fencing. No fence that passes directly through a brother's house may be used in the triangulation.

Figure E.1 shows Sample Input 1, with the brothers' locations marked by plus signs. The partition on the right uses less fencing, but it is not a solution because more than two fences lie between the brothers' locations. The correct triangulation is on the left.

Figure E.1: Sample Input 1. (a) Correct solution. (b) Incorrect solution.

Input

The input starts with a single integer nn (6≤n≤5006 \leq n \leq 500), the number of corners of the estate. Next come nn pairs of integers xix_i yiy_i (∣xi∣,∣yi∣≤3000|x_i|,|y_i|\leq 3000) giving the location of each corner, in clockwise order. No two corners coincide, the polygon is convex, and no three consecutive corners are collinear. The last two lines each contain a pair of coordinates: bx1bx_1 by1by_1 for the first brother and bx2bx_2 by2by_2 for the second (∣bx1∣,∣by1∣,∣bx2∣,∣by2∣≤3000|bx_1|,|by_1|,|bx_2|,|by_2|\leq 3000). The two brothers' locations are distinct and lie in the interior of the polygon. All coordinates are in kilometers.

Output

Output the minimum total fence length in kilometers that satisfies all the conditions above. Answers within an absolute error of 10−310^{-3} of the judges' answer are accepted. If the conditions cannot be satisfied, output the word IMPOSSIBLE.

Examples3

  1. Example 1

    Input
    6
    0 -50
    -40 10
    0 50
    80 50
    120 0
    80 -50
    -10 0
    100 0
    
    Expected output
    354.553591
    
  2. Example 2

    Input
    6
    0 -50
    -30 0
    0 50
    90 50
    120 0
    90 -50
    0 5
    90 -5
    
    Expected output
    IMPOSSIBLE
    
  3. Example 3

    Input
    12
    0 100
    50 86
    86 50
    100 0
    86 -50
    50 -86
    0 -100
    -50 -86
    -86 -50
    -100 0
    -86 50
    -50 85
    60 60
    -60 -60
    
    Expected output
    1113.370332