Area of Union of Rectangles
Tag(s):

## Easy

Problem
Editorial
Analytics

Given N rectangles in an infinite 2-D plane. Find the area of union of rectangles.

Input Format

First line contains an integer N denoting number of rectangles. Next N line contains four integers separated by a space denoting X1, Y1, X2 and Y2 respectively where (X1, Y1) denotes lower left coordinate of rectangle and (X2, Y2) denotes upper right coordinate of rectangle.

Output Format

In a single line print area of union of all N rectangles.

Constraints

1 ≤ N ≤ 100
0 ≤ X1 < X2 ≤ 1000
0 ≤ Y1 < Y2 ≤ 1000

SAMPLE INPUT
3
0 0 2 2
1 1 3 4
5 5 6 6
SAMPLE OUTPUT
10
Explanation

Area of 1st rectangle = 2 × 2 = 4
Area of 2nd rectangle = 2 × 3 = 6
Area of 3rd rectangle = 1 × 1 = 1
Area of intersection of 1st and 2nd rectangle = 1 × 1 = 1

Area of union of rectangles = Summation of area of all 3 rectangles - Area of intersection of rectangles
Area of union of rectangles = 4 + 6 + 1 - 1 = 10

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic

## CODE EDITOR

Initializing Code Editor...