Keeping the Dogs Apart

Two dogs follow their own polyline routes at the same constant speed; find the minimum distance between them while both are still walking.

Hard8GeometryTwo pointersImplementationMathNo attempts yetTime limit6sMemory limit512 MB

Problem

You look after two dogs, Shadow and Lydia. Each dog knows one favorite walk by heart. A walk is given as a list of points: the dog goes straight from the first point to the second, then straight to the third, and so on to the last point, where its doghouse stands.

Walking the dogs one after the other takes too long, so you let both of them out at the same instant. The risk is that they come close enough to bother each other, so you want to know how close they ever get.

Both dogs start at the same moment and move at exactly the same constant speed. A dog that reaches the last point of its walk goes into its doghouse and falls asleep right away, and from that moment on the distance between the dogs no longer matters, even if the other dog keeps walking for a while. A dog is still awake at the exact instant it enters its house.

Find the smallest distance between the two dogs over the time both of them are awake.

Input

The first line contains an integer nn (2n1000002 \le n \le 100000), the number of points on Shadow's walk. Each of the next nn lines contains two integers xx and yy (0x,y100000 \le x, y \le 10000), one point of the walk, in the order Shadow visits them. Two consecutive points differ in at least one coordinate.

The next line contains an integer mm (2m1000002 \le m \le 100000), the number of points on Lydia's walk. Each of the next mm lines describes one point of Lydia's walk in the same format.

Output

Print the smallest distance between the two dogs while both of them are awake, rounded to exactly six digits after the decimal point.