eolymp
bolt
Try our new interface for solving problems
Problems

Distance to Polygon

Distance to Polygon

On the plane, given a convex polygon. You need to calculate the result of a specified number of requests.

Each request represents the coordinates of a point on the plane. The result of the query is the distance from that point to a polygon (distance from a given point to the polygon is the minimum distance from that point to any point inside or on the boundary of the polygon).

Input

The first line contains number n (3n4000) - the number of vertices of the polygon.

Further, the n rows are the coordinates of the vertices in the order of traversal counterclockwise. No three vertices lie on a straight line. Each vertex is given with integer coordinates x, y (-15000x, y15000).

In the next row there are five integers: q, a, b, c, d (1q106, 0a, b, c, d15000) - the number of inquiries and conversion factors for calculating the coordinates of a subsequent request for coordinates and the results of the previous one.

In the last line there are two integers x1, y1 (-15000x1, y115000) - the coordinates of the first request.

The coordinates of the points of each subsequent requests are evaluated through the coordinates and the result of previous queries as follows. If in the i-th query, the coordinates of the points are xi, yi, and the response equals to di, then the i + 1- th query is the point with coordinates

xi+1 = ((xi + 15000) * (round(di) + a) + b) % 30001 - 15000;

yi+1 = ((yi + 15000) * (round(di) + c) + d) % 30001 - 15000;

Rounding round(di) is to the nearest integer.

Output

Print one single number - the answer to the last request with absolute or relative error 10-8.

Time limit 8 seconds
Memory limit 256 MiB
Input example #1
4
0 0
5000 0
5000 3000
0 3000
3 13 17 19 21
-1 -1
Output example #1
9407.8057484197670
Author A. Milanin
Source 2011 ACM, Ukraine, First Stage, April 9