Chinese Ink#788

Chinese Ink

2 seconds
64 megabytes
Hard

Lucca, my four-year-old daughter, loves drawing polygons on bond paper. For example, yesterday she drew two squares, a rectangle, and two triangles:

Today, she wanted to fill her figures with black Chinese ink. I helped her, resulting in the following image:

She asked me: "How many black zones do you see?" I said: two. I'm tired of answering the same question every day. Can you help us by writing a program that, given a collection of black-filled polygons, determines the number of black zones in the drawing?

For precise understanding: a black zone is a region of black-colored points on the sheet, where every pair of them may be connected by a continuous line within the region.

Input

The input consists of several test cases. Each test case is represented as follows:

  • A line with an integer (1 \le N \le 40), indicating the number of polygons in the drawing.

  • lines, one per polygon, each containing a list of 2 \cdot t integer numbers x_1 y_1 x_2 y_2 ... x_t y_t specifying the points on the boundary of the polygon (-10^4 \le x_i, y_i \le 10^4, 3 \le t \le 10). The drawn polygon is bounded by the closed path composed of the straight line segments: (x_1, y_1) - (x_2, y_2), (x_2, y_2) - (x_3, y_3), ..., (x_{t-1}, y_{t-1}) - (x_t, y_t), and (x_t, y_t) - (x_1, y_1).

    You may assume that each drawn polygon is a simple polygon (a polygon whose boundary is a non-self-intersecting closed path).

The end of the input is indicated when N = 0.

Output

For each test case in the input, print one line with the number of black zones in the drawing after filling each polygon with black Chinese ink.

Examples

Example 1

Loading
Loading