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 MBA convex polygon P lies in the plane. Put a light source at a point T outside P, and some edges of P become lit. If A and B are two consecutive vertices of P, the edge AB is lit when the area of triangle TAB is not zero and that triangle does not meet the interior of P.
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 T. The distance between T and the polygon is unrestricted, and the coordinates of T do not have to be integers.

The polygons P, P1, P2 and P3 from the second example. The figure also marks the maximal brightness.
The vertices of P are, in order, A1,A2,…,An. The polygon changes over q steps. In step j you delete one vertex that is still present and obtain a new polygon Pj. The vertices of Pj are the vertices of P that have not been deleted, in the order they had in P. Every Pj is convex as well.
Compute the maximal brightness of P and of each polygon P1,P2,…,Pq.
The first line contains the number of vertices n of the initial polygon P.
The j-th of the next n lines contains two integers xj and yj, the coordinates of vertex Aj (−109≤xj,yj≤109).
The next line contains the number of steps q (0≤q≤n−3).
The j-th of the next q lines contains an integer kj (1≤kj≤n), meaning that step j deletes vertex Akj.
The vertices of P are given counter-clockwise, no two consecutive edges are parallel, and all kj are distinct.
Print q+1 lines.
The first line holds the maximal brightness of the initial polygon P. The j-th of the next q lines holds the maximal brightness of the polygon Pj obtained after step j.
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.