Clouds

No attempts yetTime limit1sMemory limit128 MB

Problem

Today Professor Byteman contacts aliens for the first time in human history, using a special laser cannon. The sky, however, is thickly covered with clouds. He cannot predict yet which way the wind will blow, so he does not know where the best place for the cannon is either. Byteman wants to know how many times the clouds can cut off the transmission at most, when the position of the cannon and the direction of the wind combine in the worst possible way.

To keep things simple, assume the following. Every cloud in the bytean sky is a simple polygon together with its boundary, and no two clouds have a common point. Once the wind starts blowing it keeps the same direction, and it moves every cloud in that direction with the same speed. The laser cannon is a single point and it emits a laser beam straight upwards all the time. The transmission is cut off while the beam meets a cloud.

One interruption lasts from the moment a cloud starts covering the beam until the cloud leaves the beam completely. Interruptions made by different clouds are counted separately, even when they overlap in time. A cloud that only touches the beam with its boundary counts as well.

Write a program which:

  • reads the arrangement of the clouds in the sky from the standard input,
  • computes the largest number of transmission interruptions that can happen,
  • writes the result to the standard output.

Input

The first line contains one positive integer nn, the number of clouds in the bytean sky. Each of the following nn lines describes one cloud. Such a line consists of the number of sides nin_i (ni3n_i \ge 3) of the polygon that represents the cloud, followed by 2ni2 n_i integers giving the Cartesian coordinates of the vertices of that polygon, with single spaces between the numbers. The vertices are listed in the order in which they appear along the boundary of the polygon. Every coordinate lies between 109-10^9 and 10910^9. The total number of vertices of all clouds is at most 2000.

Output

Print one integer, the largest possible number of interruptions of Byteman's communication with the aliens.

Hint

The picture shows the arrangement of the first example. With the cannon at the point (3,0)(3, 0) and the wind blowing along the vector [0,1][0, -1], the transmission is cut off twice. The maximum of three interruptions happens, for instance, with the cannon at the point (0,4)(0, 4) and the wind blowing along the vector [1,0][-1, 0].