Light the Room

Given an orthogonal polygon room with a lamp, trace rays that reflect once off the walls and find the total wall length left unlit.

Hard8GeometrySimulationNo attempts yetTime limit8sMemory limit512 MB

Problem

You are given floor plans of polygonal rooms. Every wall runs parallel to the xx axis or to the yy axis. The walls are made of a special material, so they reflect light the way mirrors do, but only once. Light that has already been reflected at some point of the walls is not reflected again.

Each room holds one lamp. Light leaves the lamp in every direction and travels in straight lines. Where a ray first meets a wall, that point becomes illuminated and the ray is reflected so that the angle of reflection equals the angle of incidence. Where the reflected ray meets a wall, that point becomes illuminated and the ray stops there.

Because the walls reflect light only once, part of the walls may receive no light at all. Compute the total length of the unilluminated part of the walls.

The figure shows the second room of the sample input.

Input

The input consists of several test cases.

The first line of each test case contains one even integer NN (4N204 \le N \le 20), the number of corners. Each of the next NN lines describes one corner in counterclockwise order, and the ii-th of those lines contains two integers xix_i and yiy_i, the coordinates of the ii-th corner. The last line of the case contains xx' and yy', the coordinates of the lamp.

The input satisfies the following conditions.

  • Every coordinate is an integer whose absolute value is at most 100100.
  • Two different walls meet only at a corner they share, and nowhere else do they touch or cross.
  • The walls turn by a right angle at every corner.
  • The lamp is strictly inside the room and lies on no wall.
  • The xx coordinate of the lamp differs from the xx coordinate of every wall, and the yy coordinate of the lamp differs from the yy coordinate of every wall.

The last line of the input contains a single 00.

Output

For each test case, print the total length of the unilluminated part of the walls on one line. Round the value at the third digit after the decimal point and print exactly three digits after the decimal point.