Flight Plan Evaluation

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 MB

Problem

When 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 63706370 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.

  • No waypoint of the flight route lies within 0.10.1 km of a shoreline, that is, of a segment that belongs to a polygon.
  • No vertex of a continent polygon lies within 0.10.1 km of the flight route.

Every coordinate on the sphere is a pair of latitude and longitude in degrees. A point with latitude ±90\pm 90 is the north or the south pole, and points with latitude 00 lie on the equator.

Figure 1. The second sample input

Input

The first line contains an integer cc (1c301 \le c \le 30), the number of continents.

Each of the next cc lines describes one continent. The line starts with an integer nn (3n303 \le n \le 30), the number of vertices of the polygon, followed by the integer pairs ϕ1,λ1,,ϕn,λn\phi_1, \lambda_1, \ldots, \phi_n, \lambda_n, where ϕi\phi_i and λi\lambda_i are the latitude and the longitude of the ii-th vertex with 90ϕi90-90 \le \phi_i \le 90 and 0λi3590 \le \lambda_i \le 359.

The last line describes the flight plan. It starts with an integer mm (2m302 \le m \le 30), the number of waypoints, followed by the integer pairs ϕ1,λ1,,ϕm,λm\phi_1, \lambda_1, \ldots, \phi_m, \lambda_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.

Output

Print the total length ll of the flight in kilometers and the percentage ww 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.