Under construction

Still being built. Things may change

Diagonal slices of a rectangle union

Time limit2sMemory limit512 MB

Summary
Sum the total length of the union of axis-aligned rectangles cut by each diagonal line y = s - x for integer s in [L, R], and print the result divided by sqrt(2).
Level

Medium7 of 10

Topics
Geometry, Intervals, Prefix sum, Sorting
Solved
No attempts yet

Problem

Vera has NN rectangles whose sides are parallel to the axes. The ii-th rectangle has opposite corners (ai,bi)(a_i, b_i) and (ci,di)(c_i, d_i). Let UU be the union of the NN rectangles.

For a real number ss, the intersection of UU with the line y=s−xy = s - x is a set of disjoint segments, and some of them may shrink to a single point. Let f(s)f(s) be the total length of those segments, and let f(s)=0f(s) = 0 when the intersection is empty.

You are given integers LL and RR. Let S=∑s=LRf(s)S = \sum_{s=L}^{R} f(s), where ss runs over the integers from LL to RR. This sum is always V2V\sqrt{2} for some integer VV. Find VV.

Input

The first line contains three integers NN, LL, RR (1≤N≤1031 \le N \le 10^3, −2×108≤L<R≤2×108-2 \times 10^8 \le L < R \le 2 \times 10^8).

Each of the next NN lines contains four integers aia_i, bib_i, cic_i, did_i (−108≤ai<ci≤108-10^8 \le a_i < c_i \le 10^8, −108≤bi<di≤108-10^8 \le b_i < d_i \le 10^8).

Output

Print VV on one line.

Hint

The figure below shows the first example at s=0s = 0. There f(0)f(0) is the total length of the two thick blue segments. For that example S=72≈9.899S = 7\sqrt{2} \approx 9.899.

Three rectangles and the line y = -x

Examples2

  1. Example 1

    Input
    3 -1 3
    -2 -1 0 2
    -1 0 1 1
    1 -2 2 -1
    
    Expected output
    7
    
  2. Example 2

    Input
    5 -3 6
    -4 -4 -1 4
    -1 -4 2 -1
    -1 1 2 4
    2 -4 5 4
    -4 -1 5 1
    
    Expected output
    59