Polygon Shrinking Kit
Time limit1sMemory limit512 MB
Each polygon vertex is replaced by the midpoint toward A or toward B; among all choices keeping the vertices in convex order, find the minimum possible area.
- Level
Hard9 of 10
- Topics
- Geometry, Dynamic programming, Greedy, Math
- Solved
- No attempts yet
Problem
A Polygon Shrinking Kit is a tool used often in the geometric magic classes of Nlogonia. The kit consists of two points and in the Cartesian plane.
Consider a convex polygon given by the vertices , in this order. Shrinking this polygon with the kit must follow some rules. Each vertex of the polygon is moved exactly once: either to the midpoint of segment or to the midpoint of segment . The shrinking must produce a new convex polygon that preserves the relative order of the vertices of the original polygon. In other words, among all possible ways to apply the kit, only those whose final sequence of vertices forms a convex polygon are valid. The original convex polygon may be clockwise while a valid shrinking produces a counterclockwise convex polygon with the same vertex order. Only the relative order of the points matters, not the orientation.
In this problem, the moved points form a convex polygon in this order when all of the following hold (take and ):
- For every , the neighboring points and are different.
- At every vertex , the boundary turns in the same direction (all left turns or all right turns) or goes straight on. Going straight on means that , , lie on one line and lies between the other two. Turning back along a line is not allowed.
- The boundary goes around exactly once. That is, the result is a simple polygon that does not cross itself.
A single point or a line is not a polygon. So if a use of the kit produces anything other than a convex polygon, that use is not valid.
Geometric magic is a hard subject for most students. The teacher gave the students a convex polygon and asked them to shrink it with the kit so that its area is as small as possible, and a friend of yours begged you to solve the task for him. Find the minimum area of a polygon that a valid use of the kit can produce.

The figure above shows a valid use of the kit. The shaded polygon has the smallest area among the polygons that preserve the vertex order, and points and are the two points of the kit. Despite the name, the kit can sometimes make a polygon larger. Geometry is hard!
Input
The first line contains an integer , the number of vertices of the polygon. Each of the next lines contains two integers and , the coordinates of a vertex. The last line contains four integers , , , : the and coordinates of , then the and coordinates of .
The vertices are given in the order in which they appear on the polygon, clockwise or counterclockwise. No point appears twice, and the given polygon is convex in the sense defined above. Three consecutive vertices may lie on one line.
Constraints
Output
Print one line with the minimum area of a polygon that a valid use of the kit can produce, with exactly 3 digits after the decimal point.
Moving every vertex to the midpoint of segment gives a translated copy of the original polygon scaled by one half, so a valid use always exists. Every moved point has coordinates that are halves of integers, so the area is always a multiple of . The answer is therefore exact with 3 decimal digits, and no rounding is needed.