eolymp
bolt
Try our new interface for solving problems
Problems

Bridge Across Islands

Bridge Across Islands

Thousands of thousands years ago there was a small kingdom located in the middle of the Pacific Ocean. The territory of the kingdom consists two separated islands. Due to the impact of the ocean current, the shapes of both the islands became convex polygons. The king of the kingdom wanted to establish a bridge to connect the two islands. To minimize the cost, the king asked you, the bishop, to find the minimal distance between the boundaries of the two islands.

Input

Consists of several test cases. Each test case starts with two integers n and m (3n, m10000). Each of the next n lines contains a pair of coordinates, which describes the position of a vertex in one convex polygon. Each of the next m lines contains a pair of coordinates, which describes the position of a vertex in the other convex polygon. A line with n = m = 0 indicates the end of input. The coordinates are within the range [-10000, 10000].

Output

For each test case output the minimal distance. An error within 0.001 is acceptable.

Time limit 1 second
Memory limit 128 MiB
Input example #1
4 4
0.00000 0.00000
0.00000 1.00000
1.00000 1.00000
1.00000 0.00000
2.00000 0.00000
2.00000 1.00000
3.00000 1.00000
3.00000 0.00000
0 0
Output example #1
1.000