Under construction

Still being built. Things may change

Aerial Archeology

Time limit5sMemory limit512 MB

Summary
Given several simple polygons that may overlap, find the maximum number of polygons whose interiors a single straight line can pass through.
Level

Medium7 of 10

Topics
Geometry, Brute force, Math
Solved
No attempts yet

Problem

Andrew has a summer job with a team of aerial archeologists. The team studies the underground remains of prehistoric cultures with nuclear imaging spectroscopy. Today Andrew plans the route of a helicopter that carries the spectrometer over an area of archeological interest in the nearby lowlands. The spectrometer is sensitive and easy to damage, so the helicopter has to fly at constant speed along a perfectly straight line to keep the measurement noise low.

Several prehistoric settlements lie buried under the surface of the lowlands. Other methods already fixed their positions and boundaries, and all of those boundaries are drawn on one map that Andrew can use. The flight should pass over as many settlements as possible, so Andrew needs the straight line on the map that meets the largest number of settlements drawn there.

The settlement shapes are complicated and the settlements overlap, often chaotically, so it is not obvious where to draw the line.

Input

The input describes the shapes and the positions of the settlements on the map. Each settlement is a simple polygon: no two of its non-adjacent boundary segments touch or intersect each other. Different polygons may overlap.

The input holds several test cases and ends at the end of the file. Each case starts with a line containing one positive integer NN, the number of polygons on the map. The descriptions of the NN polygons follow. Each description starts with a line containing one integer MM (M≥3M \ge 3), the number of vertices of the polygon. Each of the next MM lines contains two integers xx and yy separated by a space, the coordinates of one vertex. The vertices are listed in clockwise order along the polygon boundary. All coordinates are integers with absolute value at most 1000010000. The total number of vertices of all polygons in one test case is at most 10001000.

Output

For each test case, print one line with a single integer PP, the maximum number of polygons on the map that one straight line can intersect. Only intersections of the line with the interior of a polygon count. A line that touches a polygon along its boundary but passes through no point of its interior does not intersect that polygon.

Examples2

  1. Example 1

    Input
    3
    4
    0 0
    0 1
    1 1
    1 0
    4
    1 2
    1 3
    2 3
    2 2
    5
    2 1
    2 2
    9 2
    10 3
    10 1
    
    Expected output
    2
    
  2. Example 2

    Input
    1
    3
    0 0
    1 3
    2 0
    2
    4
    0 0
    0 2
    2 2
    2 0
    4
    5 0
    5 2
    7 2
    7 0
    
    Expected output
    1
    2