This page is still under construction.

Parts of this page are still being built. What you see may change.

Keep in Touch

Time limit1sMemory limit1024 MB

Level

Not classified yet

Solved
No attempts yet

Problem

Two agents, A and B, are known as a great combination. They are carrying out an infiltration mission to a secret base. Because the base has strict security, the two agents have decided to follow the prechecked safe infiltration routes RAR_A and RBR_B, respectively. Each route is a two-dimensional polyline, a series of line segments.

Each agent starts at the starting end of the first segment of its route. The mission is over when both agents are on the finishing ends of the last segments of their routes at the same time.

During the mission, each agent can move forward or backward at any speed, or stop for a moment, as long as its movement along the route is continuous. An agent cannot jump to a new position. Segments may cross or overlap, but they cannot be used for movement. Precisely, an agent on one segment can move to another segment only in these cases.

  • The destination is the next segment on the route, and the agent is at the finishing end of the current segment.
  • The destination is the previous segment on the route, and the agent is at the starting end of the current segment.

For example, in Figure G-1, the agent must reach the finishing end of segment 3-4 of RBR_B, which is (−1,1)(-1, 1), before it can move to segment 4-5. When the agent moves from segment 2-3 to segment 3-4, it passes (2,1)(2, 1), the finishing end of the last segment. That passage does not count, because the agent is not considered to be at the finishing end of the last segment at that time.

Figure G-1: Infiltration routes for the first dataset

Figure G-2: Infiltration routes for the second dataset

The two agents must always stay within communication range of each other. A stronger signal allows a longer communication distance, but it also raises the chance of interception. Find the minimum communication distance that lets the agents complete the mission with suitable movements.

Input

The input consists of multiple datasets, each in the following format.

n
xA,1 yA,1
 ⋮
xA,n yA,n
m
xB,1 yB,1
 ⋮
xB,m yB,m

nn is the number of vertices of route RAR_A. nn is an integer from 2 to 40, inclusive.

xA,ix_{A,i} and yA,iy_{A,i} (1≤i≤n1 \le i \le n) are the coordinates of the ii-th vertex. They are integers satisfying −1000≤xA,i≤1000-1000 \le x_{A,i} \le 1000 and −1000≤yA,i≤1000-1000 \le y_{A,i} \le 1000. For 1≤i≤n−11 \le i \le n-1, (xA,i,yA,i)(x_{A,i}, y_{A,i}) is the starting end of the ii-th segment, and (xA,i+1,yA,i+1)(x_{A,i+1}, y_{A,i+1}) is its finishing end. Every segment has nonzero length, so xA,i≠xA,i+1x_{A,i} \ne x_{A,i+1} or yA,i≠yA,i+1y_{A,i} \ne y_{A,i+1} holds.

mm and the pairs xB,jx_{B,j} and yB,jy_{B,j} (1≤j≤m1 \le j \le m) describe route RBR_B. The format and constraints are the same as for RAR_A.

The input ends with a line containing 0.

Output

For each dataset, print on one line the maximum distance between the two agents during the mission, when the agents move so that this maximum is as small as possible. The error must not exceed 10−810^{-8}. An answer is accepted if either its relative error or its absolute error is within this limit.

Examples1

  1. Example 1

    Input
    2
    0 0
    2 0
    5
    0 -1
    2 -1
    2 1
    -1 1
    2 1
    4
    0 0
    4 6
    0 3
    8 6
    3
    0 0
    4 3
    8 6
    10
    40 15
    40 20
    40 15
    45 10
    50 12
    50 10
    50 15
    60 15
    65 20
    70 18
    10
    40 10
    40 15
    45 20
    50 18
    50 15
    50 20
    60 20
    60 15
    65 10
    70 12
    0
    
    Expected output
    1.414213562373
    2.400000000000
    9.284766908853