eolymp
bolt
Try our new interface for solving problems
Problems

Around the Track

Around the Track

Time limit 1 second
Memory limit 128 MiB

In order to compare race tracks, we wish to compute their lengths. A racetrack is strictly two-dimensional (no elevation). It is described by two simple polygons, where one is completely contained inside the other. The track is the region between these two polygons. We define the length of the track as the absolute minimum distance that one needs to travel in order to complete a lap. This could involve traveling on the very edge of the track and arbitrarily sharp cornering.

prb7851.gif

Illustration of sample input number 3 together with the shortest route around the track (dashed).

Input data

Consists of:

  • one line with one integer n (3n50), the number of vertices of the inner polygon;

  • n lines, the i-th of which contains two integers x[i] and y[i] (5 000x[i], y[i]5 000): the coordinates of the i-th vertex of the inner polygon;

  • one line with one integer m (3m50), the number of vertices of the outer polygon;

  • m lines, the i-th of which contains two integers x[i] and y[i] (5 000x[i], y[i]5 000): the coordinates of the i-th vertex of the outer polygon.

For both polygons, the vertices are given in counterclockwise order. The borders of the two polygons do not intersect or touch each other.

Output data

Output one line with one floating point number: the length of the race track. Your answer should have an absolute or relative error of at most 10^(-6).

Examples

Input example #1
3
1 1
2 1
1 2
3
0 0
4 0
0 4
Output example #1
3.41421356237309
Input example #2
5
1 1
5 1
5 5
3 3
1 5
4
0 0
6 0
6 6
0 6
Output example #2
16
Input example #3
5
1 1
5 1
5 5
3 3
1 5
5
0 0
6 0
6 6
3 4
0 6
Output example #3
16.4721359549996
Source 2014 ACM North Western European Regional Contest (NWERC), Ноябрь 30, Задача A