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 (3 ≤ n ≤ 4000) - 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 (-15000 ≤ x, y ≤ 15000).
In the next row there are five integers: q, a, b, c, d (1 ≤ q ≤ 10^6
, 0 ≤ a, b, c, d ≤ 15000) - 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 x[1]
, y[1]
(-15000 ≤ x[1]
, y[1]
≤ 15000) - 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 x[i]
, y[i]
, and the response equals to d[i]
, then the i + 1- th query is the point with coordinates
x[i+1]
= ((x[i]
+ 15000) * (round(d[i]
) + a) + b) % 30001 - 15000;
y[i+1]
= ((y[i]
+ 15000) * (round(d[i]
) + c) + d) % 30001 - 15000;
Rounding round(d[i]
) is to the nearest integer.
Output
Print one single number - the answer to the last request with absolute or relative error 10^(-8)
.