Turf Wars

Each gang owns disjoint axis-aligned rectangles; pick exactly one rectangle to drop per gang so that no two kept rectangles from different gangs overlap, and report whether this is possible.

Hard8GeometryBrute forceBacktrackingImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

There are NN gangs in a city. Each gang occupies several rectangular territories, and any overlap between territories of different gangs causes a dispute.

NN satisfies 2N3002 \le N \le 300, and gang ii owns MiM_i territories. Every territory is a rectangle whose sides are parallel to the xx and yy axes, given by its lower-left corner (x1,y1)(x_1, y_1) and its upper-right corner (x2,y2)(x_2, y_2). The coordinates are integers satisfying 0x1<x2<10000000 \le x_1 < x_2 < 1000000 and 0y1<y2<10000000 \le y_1 < y_2 < 1000000.

A dispute region is a part where two territories of different gangs overlap with positive area. Territories that meet only along an edge or at a point are not a dispute region.

Each gang must give up exactly one of its MiM_i territories. Decide whether all dispute regions can be eliminated this way.

Input

The first line contains the number of gangs NN.

Then the territories of gang 11 through gang NN follow in order. The first line for gang ii contains the number of territories MiM_i (2Mi152 \le M_i \le 15). Each of the following MiM_i lines contains x1x_1, y1y_1, x2x_2, y2y_2, the coordinates of the lower-left and upper-right corners of one territory, separated by spaces.

Territories owned by one gang never overlap each other.

Output

If the gangs can eliminate every dispute region by each giving up one territory, print YES. Otherwise, print NO.

Hint

If one territory overlaps two different territories of another gang, it can never be kept and must be given up. Conversely, every territory overlapping a kept territory must be given up, so a single choice can force the choices of other gangs in a chain.