Hide

Problem D
The Rectangles Are Surrounding Us!

You are given a list of rectangle boundaries. Each rectangle boundary is on integer coordinates. The rectangles surround squares on the coordinate grid. Your job is to determine the total number of such grid squares that are surrounded by at least one of the given rectangles.

Input

Input consists of a set of $1$ to $10$ cases. Each case starts with the number of rectangles $0 < n \le 50$. Following this are $n$ rectangles, each given as four integers, $a$ $b$ $c$ $d$, where $a < c$ and $b < d$. The point $(a,b)$ defines the bottom left corner of the rectangle and the point $(c,d)$ defines the top right. All coordinates are between $0$ and $500$ (inclusive). Input ends when $n$ is $0$.

Output

For each set of rectangles, print the total number of grid points they surround.

Sample Input 1 Sample Output 1
1
1 1 2 2
1
10 10 19 19
2
10 10 19 19
15 15 24 24
0
1
81
146

Please log in to submit a solution to this problem

Log in