Maximal polygon brightness

Given a convex polygon and a sequence of vertex deletions, compute after each deletion the largest total length of edges that a single external light point can illuminate.

Hard9GeometryDynamic programmingDivide and conquerGreedyNo attempts yetTime limit3sMemory limit1024 MB

Problem

A convex polygon PP lies in the plane. Put a light source at a point TT outside PP, and some edges of PP become lit. If AA and BB are two consecutive vertices of PP, the edge ABAB is lit when the area of triangle TABTAB is not zero and that triangle does not meet the interior of PP.

The brightness of the polygon is the sum of the lengths of the lit edges. The maximal brightness is the largest brightness you can reach by choosing the best point TT. The distance between TT and the polygon is unrestricted, and the coordinates of TT do not have to be integers.

The polygons PP, P1P_1, P2P_2 and P3P_3 from the second example. The figure also marks the maximal brightness.

The vertices of PP are, in order, A1,A2,,AnA_1, A_2, \dots, A_n. The polygon changes over qq steps. In step jj you delete one vertex that is still present and obtain a new polygon PjP_j. The vertices of PjP_j are the vertices of PP that have not been deleted, in the order they had in PP. Every PjP_j is convex as well.

Compute the maximal brightness of PP and of each polygon P1,P2,,PqP_1, P_2, \dots, P_q.

Input

The first line contains the number of vertices nn of the initial polygon PP.

The jj-th of the next nn lines contains two integers xjx_j and yjy_j, the coordinates of vertex AjA_j (109xj,yj109-10^9 \le x_j, y_j \le 10^9).

The next line contains the number of steps qq (0qn30 \le q \le n - 3).

The jj-th of the next qq lines contains an integer kjk_j (1kjn1 \le k_j \le n), meaning that step jj deletes vertex AkjA_{k_j}.

The vertices of PP are given counter-clockwise, no two consecutive edges are parallel, and all kjk_j are distinct.

Output

Print q+1q + 1 lines.

The first line holds the maximal brightness of the initial polygon PP. The jj-th of the next qq lines holds the maximal brightness of the polygon PjP_j obtained after step jj.

Round every value to six decimal places and print all six digits, trailing zeros included. In every test the answer stays far from a rounding boundary, so double precision arithmetic prints the same digits.