#P6081. [USACO05DEC] Barn Expansion G

[USACO05DEC] Barn Expansion G

Description

Farmer John has NN (1N250001 \leq N \leq 25000) rectangular barns. Their walls are parallel to the coordinate axes, and their coordinates are within the range [0,106][0,10^6]. It is guaranteed that no two barns overlap, but they may share a common wall.

As the number of cows keeps increasing, FJ plans to expand the barns. A barn is expandable if and only if none of its walls shares any common segment with the walls of other barns. If two barns share a common corner, then neither of them is expandable.

Compute how many barns are expandable.

Input Format

The first line contains an integer NN.

The next NN lines each contain four integers, representing the coordinates of the lower-left corner and the upper-right corner of a barn.

Output Format

Output the number of expandable barns.

5
0 2 2 7
3 5 5 8
4 2 6 4
6 1 8 6
0 0 8 1
2

Hint

The first two barns are expandable.

Translated by ChatGPT 5