QOJ.ac

QOJ

Time Limit: 15 s Memory Limit: 512 MB Total points: 10

#6024. Giewont [A]

Statistics

Bajtazar, a well-known amateur mountain hiker, is setting off on a new expedition. This time, he was encouraged by photos from the Polish Tatra Mountains and decided to conquer the peaks of Giewont. He is therefore interested in how high he will have to climb.

Unfortunately, the map of the Tatras he purchased in Bajtocja leaves much to be desired and is highly incomplete.

In fact, the only things marked on the map are contour lines. We can introduce a rectangular coordinate system on the map; then, each contour line is a simple closed polygonal chain with integer coordinates of vertices and sides parallel to the coordinate axes. The contour lines do not intersect or touch, but they can be nested within each other arbitrarily. We assume that there is one "outermost" contour line that contains all the others.

Bajtazar would like to read the height of the highest mountain from the map, but the height at which the contour lines are located is not written next to them. Bajtazar therefore decided to estimate this height (nomen omen) from above. Since a mountain on the map will be represented by a sequence of contour lines, each of which is contained within the previous one, Bajtazar assumed that the longer such a sequence is, the potentially higher the mountain can be.

Unfortunately, he suspects that the map contains only a portion of the contour lines, and in reality, the mountains are even higher. He is now trying to draw new contour lines on the map to obtain the highest possible mountain. Help Bajtazar and write a program that will perform this task. The new contour lines must be simple closed polygonal chains that satisfy the same conditions as the contour lines on the map (integer coordinates, sides parallel to the coordinate axes, no intersections with other contour lines, and containment within the "outermost" contour line).

Input

The first line of input contains a single positive integer $n$ denoting the number of contour lines on the map. Each of the following $n$ lines contains a description of one contour line. The description begins with an even integer $k$, denoting the number of vertices of the contour line. This is followed by a sequence of $k$ integers $x_1, x_2, \dots, x_k$ ($-10^8 \le x_i \le 10^8$); the consecutive vertices of the contour line are $(x_1, x_2), (x_3, x_2), (x_3, x_4), (x_5, x_4), \dots, (x_{k-1}, x_k), (x_1, x_k)$.

The total number of vertices across all contour lines does not exceed $50\,000$. The contour lines are given in arbitrary order. When traversing any contour line in the order of its vertices, its "interior" is always on the left side.

Output

Output a single integer representing the height of the highest mountain (i.e., the longest sequence of nested contour lines) that can be obtained by drawing new contour lines.

Examples

Input 1

6
4 3 5 6 8
8 7 4 9 5 8 6 9 7
4 13 5 14 6
10 8 1 17 12 8 11 0 2 4 0
4 11 4 15 8
4 10 10 13 11

Output 1

5

Note

Explanation for the example: In the drawing, the contour lines on the map are marked with solid lines. There is a mountain on the map consisting of three nested contour lines. Drawing three new contour lines (dashed lines) allows for obtaining a mountain consisting of five nested contour lines.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.