Invalid Crashout
After crashing out from the first AllUni competitive programming competition, Maged's team decided to launch some nukes at Adelaide. Now, all that remains of Adelaide are a collection of walls, running either North-South or East-West. To rebuild the city, we need to do is figure how many "valid rooms" are left among the rubble.
A valid room is a collection of walls that form a rectangle, and valid rooms can overlap each other. For example, there are
valid rooms in the below diagram:
Help find all the valid rooms among the rubble!
Input
The first line contains an integer (
), the number of walls left in Adelaide.
The next lines contain
,
,
, and
, representing the start and end points of the wall. Either
or
, but never both.
Output
Output the number of "valid rooms" left in the rubble of Adelaide.
Clarifications
- Walls can be repeated, or lie completely inside each other.
- Two walls that overlap along the same line should be merged and considered a single wall.
- Although the coordinate system in this problem doesn't matter, the images show right being +x and up being +y.
Example
Input 1
5
1 1 1 5
3 1 3 5
0 2 4 2
0 4 4 4
0 5 4 5
Output 1
3
This test case looks like:
Input 2
6
0 0 0 10
0 10 10 10
10 10 10 20
10 20 20 20
20 20 20 0
20 0 0 0
Output 2
0
This test case looks like:
Comments