Laser in a Mirrored Polygon
The laser is positioned inside a convex n-gon with mirrored walls. When activated, the laser beam reflects off the walls. Determine the angle α relative to the x-axis at which the laser should be aimed so that the beam first reflects off the first wall, then the second, continuing in sequence, and finally, after reflecting off the n-th wall, returns to its starting point. The beam must not reflect off any vertices of the n-gon.
Input
The first line of the input provides the number of vertices of the polygon, n (3 ≤ n ≤ 100). The next n lines list the coordinates of the polygon's vertices in a clockwise order. The first wall is defined by the line segment between the first and second vertices, the second wall by the segment between the second and third vertices, and so forth. The last line of the input specifies the coordinates of the laser, which is treated as a point. All coordinates are real numbers with absolute values not exceeding 1000. The vertices can be listed in either clockwise or counterclockwise order.
Output
If a solution exists, output the required angle α (in degrees) with a precision error not exceeding 0.0001 degrees. The angle should be within the range (0 ≤ α < 360). If no solution exists, output -1.