This page is still under construction.

Parts of this page are still being built. What you see may change.

Rock Festival

Time limit1sMemory limit256 MB

Summary
Add up the areas of rectangles that touch by edge or corner and print the largest connected patch.
Level

Medium7 of 10

Topics
Union-find, Geometry, Sorting
Solved
No attempts yet

Problem

A rock festival came to Deokhwi's town and the band he likes played there. The townspeople like quiet, so they drove the band out. Deokhwi got angry and decided to invite the band to the backyard of his own mansion and ask for a show.

The backyard has not been used for a long time, so weeds grew here and there. Deokhwi does not want to mow them, so he will use the largest patch of bare ground as the stage. The bare ground consists of several rectangles, and rectangles that touch each other count as one patch. Two rectangles that meet at a single corner point also count as touching.

Find the area of the largest patch of bare ground in the backyard.

Input

The first line contains the number of weed free plots NN. (0<N≤500000 < N \le 50000)

Each of the next NN lines describes one plot as XX, YY, WW, HH in that order. It is the rectangle whose lower left corner is (X,Y)(X, Y), whose width is WW, and whose height is HH. (0<W,H≤5000 < W, H \le 500)

Every side of every plot is parallel to the xx axis or the yy axis. XX, YY, X+WX+W, and Y+HY+H all fit in a signed 32 bit integer. The interiors of two different plots never overlap.

Output

Print the area of the largest patch of bare ground on the first line.

Hint

In the first example the 8 plots split into four patches. The fourth and fifth plots form a patch of area 16, the second and eighth form a patch of area 20, the first, third, and seventh form a patch of area 15, and the sixth alone forms a patch of area 16. So the answer is 20.

Examples3

  1. Example 1

    Input
    8
    14 1 2 2
    16 9 1 5
    11 3 5 2
    3 4 2 5
    5 9 3 2
    21 3 2 8
    13 2 1 1
    13 8 3 5
    
    Expected output
    20
    
  2. Example 2

    Input
    1
    0 0 500 500
    
    Expected output
    250000
    
  3. Example 3

    Input
    2
    0 0 2 2
    2 2 3 3
    
    Expected output
    13