Given continent polygons and flight waypoints on a sphere, compute the total flight length and the share flown over water.
Hard8GeometryMathNo attempts yetTime limit6sMemory limit256 MBWhen you fly between two places, a good flight plan matters. Fuel consumption and the weather forecast, above all the winds, are the usual concerns. This problem measures something else: how much of the flight passes over water and how much passes over land. The number does not change the flight itself, but many passengers prefer flying over land, either because open water makes them nervous or because the view is a little more interesting.
Assume the earth is a perfect sphere of radius 6370 km. Each continent is a polygon on that sphere, a closed sequence of segments where the segment between two points is the shortest spherical arc between them. The two endpoints of a segment are never the same point and never antipodal (diametrically opposite). A flight route joins waypoints by segments in the same way, but unlike the segments of a polygon the segments of a route may cross each other, and the route does not have to end where it started.
Two more assumptions keep the problem simple.
Every coordinate on the sphere is a pair of latitude and longitude in degrees. A point with latitude ±90 is the north or the south pole, and points with latitude 0 lie on the equator.

Figure 1. The second sample input
The first line contains an integer c (1≤c≤30), the number of continents.
Each of the next c lines describes one continent. The line starts with an integer n (3≤n≤30), the number of vertices of the polygon, followed by the integer pairs ϕ1,λ1,…,ϕn,λn, where ϕi and λi are the latitude and the longitude of the i-th vertex with −90≤ϕi≤90 and 0≤λi≤359.
The last line describes the flight plan. It starts with an integer m (2≤m≤30), the number of waypoints, followed by the integer pairs ϕ1,λ1,…,ϕm,λm in the same format.
A continent never crosses itself. No continent touches or contains another continent. The vertices of a continent are given counterclockwise, so when you walk from the first vertex to the second one the interior of the continent is on your left.
The first and the last waypoint of the route always lie inside a continent, and it does not have to be the same continent.
Print the total length l of the flight in kilometers and the percentage w of the flight that is over water, on one line separated by a single space. Print both numbers rounded to exactly four digits after the decimal point.