Crow

No attempts yetTime limit3sMemory limit256 MB

Problem

A crow lives on the two dimensional plane. Today it flew around all day again, looking for food and for anything shiny.

The part of the plane with y<0y < 0 is ground, so the crow cannot go there. There is also one mountain, and the crow cannot go inside it either. The mountain is described by NN vertices P1(x1,y1)P_1(x_1, y_1) through PN(xN,yN)P_N(x_N, y_N). The values xix_i are given in increasing order, every yiy_i satisfies yi0y_i \ge 0, and y1=yN=0y_1 = y_N = 0. Joining P1P_1 through PNP_N in order and then joining PNP_N back to P1P_1 gives the boundary of the mountain. The crow may travel along the edges of the mountain, but it cannot enter the interior.

The crow made M1M-1 moves today. It started at Q1(X1,Y1)Q_1(X_1, Y_1), went to Q2(X2,Y2)Q_2(X_2, Y_2) next, and so on until it visited QM(XM,YM)Q_M(X_M, Y_M) and ended the day. The crow is clever, so each move from QiQ_i to Qi+1Q_{i+1} took a shortest path that passes through neither the interior of the ground nor the interior of the mountain. Write a program that computes the total distance the crow travelled today.

Input

The first line contains NN (3N10003 \le N \le 1000).

The ii-th of the next NN lines contains xix_i and yiy_i (104xi104-10^4 \le x_i \le 10^4, 0yi1040 \le y_i \le 10^4) separated by one space. xi<xi+1x_i < x_{i+1} holds for every ii with 1i<N1 \le i < N, and y1=yN=0y_1 = y_N = 0.

The next line contains MM (2M10002 \le M \le 1000).

The ii-th of the next MM lines contains XiX_i and YiY_i (104Xi104-10^4 \le X_i \le 10^4, 0Yi1040 \le Y_i \le 10^4) separated by one space. No (Xi,Yi)(X_i, Y_i) lies inside the mountain. It may lie on the boundary.

Output

Print the total distance the crow travelled, rounded to six digits after the decimal point, on one line. Always print all six digits.

Hint

The terrain of the first example is shown below. Green is the mountain and brown is the ground. The crow can move through the light blue area and along the edges of the mountain and the ground.

The next two pictures show the two moves of the crow. The first move has length 525\sqrt{2} and the second has length 5+55 + \sqrt{5}, so the two together are about 14.30713614.307136.