Two Plates
Limits: 4 sec., 512 MiB
It’s not a secret that Zenyk loves food. One day he got his hands on a buffet table with lots of exotic fruits.
For simplicity, lets consider the table as a plane, and plates as a rectangles with sides parallel to the axes. There are \(N\) plates on the table. Please note that the plates might intersets.
Unfortunately, Zenyk has only two hands, so he’s gonna pick two plates. Apart from that, the following two conditions must be fulfilled:
The two plates must have non-zero area of intersection.
There should be no other plate with non-zero area of intersection with any of the two plates.
Help Zenyk find out the number of pairs of plates that he can choose.
Input
The first line contains a single integers \(N\) — the number of plates. The following \(N\) lines describe plates, one plate per line. The description consists of four integers \(x_1\) \(y_1\) \(x_2\) \(y_2\) — the coordinates of lower-left and upper-right corners of the plate.
Output
Print a single integer — the number of ways to choose two plates
Constraints
\(2 \le N \le 10^5\),
\(0 \le x_1 < x_2 \le 10^6\),
\(0 \le y_1 < y_2 \le 10^6\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 3 0 0 2 2 1 1 3 3 4 7 7 11 | 1 |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|