Under construction

Still being built. Things may change

Screamers in the Storm

Time limit2sMemory limit512 MB

Summary
Given a rectilinear roof polygon with two pigeon positions, compute the shortest walking-and-flying path length across the sloped roof surface.
Level

Hard10 of 10

Topics
Geometry, Shortest path, Simulation
Solved
No attempts yet

Problem

You may not know that the official name of the "common" urban pigeon you see every day in a city is "rock pigeon" or "rock dove". Rock pigeon Rocky Dave is in love with Columba Livia, a young female rock pigeon who is interested in rock music, pigeons, and everything related to them. By coincidence, on a sunny autumn afternoon, we find them in the city suburbs sitting on the roof of the same building.

To show off his confident athletic gait, Rocky Dave decides not to fly over the roof to his beloved, but to walk toward her instead. The roof is not a modern flat roof. It is a classical roof made of slopes. The building consists of several smaller buildings joined together, so its floor plan is somewhat complex. The "straight line" Dave intends to follow appears straight only when viewed from above. Dave might have to climb up, go over the ridge, descend into a roof valley on the other side, climb again, and so on.

We know the exact floor plan of the building, the angle of the slopes (all slopes have the same angle), and the original positions of both pigeons on the roof. Given these data, compute the exact length of Rocky Dave's journey, provided that Columba Livia does not leave her position before Rocky Dave reaches her.

If the path leaves the building boundary, Dave's plan is this: whenever he reaches a rain gutter on the roof edge, he flies straight at the same height toward Columba Livia until he reaches a rain gutter on another side of the building. There he continues on foot.

To make the situation unambiguous, we give a geometric model of the roof. Let Z be a simple polygon in the x-y plane. A simple polygon is a polygon whose boundary is a closed curve that does not touch or intersect itself. An acceptable pyramid is a pyramid whose base is an axis-parallel square in the x-y plane and whose apex is directly above the base center. The pyramid height is exactly half the length of the base side. No part of the base of an acceptable pyramid lies outside Z. An acceptable pyramid may have zero base side length and zero height, in which case it consists of a single point, which is also its apex.

A point X in or above the x-y plane is a point of the roof of Z if and only if X is the apex of an acceptable pyramid and no point directly above X is the apex of an acceptable pyramid.

Input

The first line contains five integers: N (4 ≤ N ≤ 400), the number of corner points of the polygon formed by the edges of the floor plan, followed by the x and y coordinates of Rocky Dave and the x and y coordinates of Columba Livia.

Each of the next N lines contains the x and y coordinates of one corner point. The points are listed in counter-clockwise order. Every side of the building is parallel to one of the axes.

Neither pigeon is located outside the given polygon. All input coordinates are integers with absolute value at most 10510^5.

Output

Output the length of Rocky Dave's journey. The answer must have an absolute or relative error less than 10−710^{-7}.

Hint

Figure 1: Illustration of the first and second sample inputs.

Examples2

  1. Example 1

    Input
    4 3 0 3 4
    0 0
    4 0
    4 4
    0 4
    
    Expected output
    4.828427124746
    
  2. Example 2

    Input
    6 1 1 5 5
    0 0
    2 0
    2 4
    6 4
    6 6
    0 6
    
    Expected output
    6.292528739884