Under construction

Still being built. Things may change

Colored Paper

Interview

Time limit1sMemory limit64 MB

Summary
Compute the area of each of N overlapping axis-aligned rectangles that stays visible after later rectangles cover it.
Level

Easy3 of 10

Topics
Simulation, Matrix, Implementation
Solved
No attempts yet

Problem

Rectangular sheets of colored paper, each a different color, are placed on a plane one at a time until NN sheets are down. No sheet is placed at an angle, so any two sides of any two sheets are either parallel or perpendicular. Figure 1 shows sheets 1, 2, and 3 placed in that order.

Figure 1

Placing a fourth sheet as in figure 2 hides sheet 3 completely. Sheets 1 and 2 are partly hidden, and sheet 4 is fully visible.

Figure 2

Write a program that computes the visible area of each sheet after the NN sheets are placed at the given positions, in the given order.

Input

The first line has the number of sheets NN (1≤N≤1001 \le N \le 100). Each of the next NN lines describes one sheet, in the order the sheets are placed.

The plane is a grid at most 1001 cells wide and at most 1001 cells tall. Each cell is a square of width 1, height 1, and area 1.

Take a grid 6 cells wide and 6 cells tall as an example. The pair (a,b)(a, b) written inside a cell is the number of that cell. The bottom left cell is (0,0)(0, 0) and the top right cell is (5,5)(5, 5).

A sheet is given by four integers xx, yy, ww, hh: the number of its bottom left cell, its width, and its height. The gray sheet in the picture above has its bottom left cell at (1,4)(1, 4), width 3, and height 2, so it is written as 1 4 3 2. The width and the height are integers of at least 1, and no sheet reaches outside the grid.

Output

Print the visible area of each sheet as one integer on its own line, in the order the sheets are given in the input. If a sheet is not visible at all, print 0.

Examples3

  1. Example 1

    Input
    2
    0 0 10 10
    2 2 6 6
    
    Expected output
    64
    36
    
  2. Example 2

    Input
    3
    0 2 10 10
    7 9 8 4
    8 4 10 6
    
    Expected output
    81
    25
    60
    
  3. Example 3

    Input
    4
    0 2 10 10
    7 9 8 4
    8 4 10 6
    6 0 12 10
    
    Expected output
    62
    24
    0
    120