Around the Track

No attempts yetTime limit2sMemory limit256 MB

Problem

To compare race tracks you need their lengths. A track is flat, with no elevation. It is described by two simple polygons, one of which lies completely inside the other. The track is the region between the two polygons, and both boundaries belong to the track.

The length of the track is the shortest distance you have to travel to complete one lap, that is, the length of the shortest closed route that stays inside the track and goes around the inner polygon once. Such a route may run along the very edge of the track, and it may turn arbitrarily sharply at a corner.

Input

The input consists of:

  • one line with one integer nn, the number of vertices of the inner polygon (3n503 \le n \le 50);
  • nn lines, the iith of which contains two integers xix_i and yiy_i, the coordinates of the iith vertex of the inner polygon (5000xi,yi5000-5000 \le x_i, y_i \le 5000);
  • one line with one integer mm, the number of vertices of the outer polygon (3m503 \le m \le 50);
  • mm lines, the iith of which contains two integers xix_i and yiy_i, the coordinates of the iith vertex of the outer polygon (5000xi,yi5000-5000 \le x_i, y_i \le 5000).

All coordinates are integers. For both polygons the vertices are given in counterclockwise order, and the boundaries of the two polygons neither intersect nor touch each other.

Output

Print the length of the track on one line, rounded to exactly six digits after the decimal point. Print all six digits even when the length is an integer.