Chinese Ink
Lucca, my four-years-old daughter, loves drawing polygons in 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, obtaining the next result:
She asked me: how many black zones do you see?. I said: two. I'm bored answering the same question everyday. Can you help us writing a program that, given a collection of black filled polygons, determines the number of black zones on the drawing?
For a precise understanding: a black zone is a region of black coloured 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 N (1 ≤ N ≤ 40) which indicates the number of polygons in the drawing.
N lines, one per polygon, each one containing a list of 2·t integer numbers x_1 y_1 x_2 y_2 ... x_t y_t specifying the points in the boundary of the polygon (-10^4 ≤ x_i, y_i ≤ 10^4, 3 ≤ t ≤ 10). The drawn polygon is bounded by the closed path composed of the straight line segments
,
, ...,
, and
. You can suppose that the 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 case in the input, print one line with the number of black zones in the drawing after filling each one of the polygons with black chinese ink.