Electricity

Place a power plant at an integer intersection minimizing the sum over axis-aligned rectangles of the Manhattan distance to the nearest rectangle corner.

Hard8GeometryBinary searchDivide and conquerNo attempts yetTime limit1.5sMemory limit128 MB

Problem

In the 19th century, electricity was slowly coming into general use. One of the first large-scale uses of electricity was lighting public spaces. The company Edison Patents & Theft Inc. decided to show the New York city authorities how useful electricity is by lighting the more important streets of Manhattan. Manhattan has a very regular layout made up only of streets (parallel to the XX axis) and avenues (parallel to the YY axis).

Because the technology is still in its infancy, lighting is installed one quarter at a time. A quarter is a rectangle whose sides lie on two streets and two avenues. Each quarter is given by two opposite corners of the rectangle, and these corners always lie on intersections of streets and avenues. Quarters may overlap. Each quarter is lit by one closed circuit. Because of technical limits, that circuit has only four break points, one at each corner of the quarter.

After deciding which quarters to light, the company wants to find the intersection where it is cheapest to build a power plant. The cost of the power plant is the sum of its distances to every quarter. The distance from the power plant to a quarter is the number of streets plus the number of avenues between the power plant and the nearest corner of that quarter, that is, the Manhattan distance between the two points. If the power plant is at (px,py)(p_x, p_y), its distance to a corner (vx,vy)(v_x, v_y) is pxvx+pyvy|p_x - v_x| + |p_y - v_y|, and its distance to the quarter (x1,y1,x2,y2)(x_1, y_1, x_2, y_2) is the minimum of this value over the four corners (x1,y1)(x_1, y_1), (x1,y2)(x_1, y_2), (x2,y1)(x_2, y_1), and (x2,y2)(x_2, y_2). The power plant can be built at any intersection with integer coordinates. The figure shows one possible choice of quarters and a power plant location.

Use 21st-century technology to solve their problem: for the given quarters, find the minimum possible cost of the power plant.

Input

The first line contains NN (1N200000)(1 \le N \le 200\,000), the number of quarters.

Each of the next NN lines describes one quarter with four coordinates x1x_1, y1y_1, x2x_2, and y2y_2, where x1<x2x_1 < x_2 and y1<y2y_1 < y_2. All coordinates are positive integers less than 10710^7 (ten million).

Output

Print one number on a single line: the minimum possible cost of the power plant.