Expected Bounding Box (Stretch)


This is a stretch problem.

There are nn points on the plane. Point ii has coordinates (xi,yi)(x_i, y_i) and is selected independently with probability ai/bia_i / b_i.

Let SS be the random set of selected points, and let RR be the smallest axis-aligned bounding rectangle containing every point of SS. The geometric area of RR is

(max⁡i∈Sxi−min⁡i∈Sxi)⋅(max⁡i∈Syi−min⁡i∈Syi)(\max_{i \in S} x_i - \min_{i \in S} x_i) \cdot (\max_{i \in S} y_i - \min_{i \in S} y_i).

If SS has fewer than two points, or all selected points share the same xx-coordinate or the same yy-coordinate, this area is 00.

Output the expected area of RR.

It can be shown that the answer can be expressed as a rational number P/QP/Q in lowest terms with QQ coprime to 109+710^9 + 7. Output P⋅Q−1 mod (109+7)P \cdot Q^{-1} \bmod (10^9 + 7).

Input

The first line contains an integer nn.

Each of the next nn lines contains four integers xix_i, yiy_i, aia_i, and bib_i.

Output

Print a single integer: the expected area modulo 109+710^9 + 7.

Constraints

  • 1≤n≤2⋅1051 \le n \le 2 \cdot 10^5
  • −109≤xi,yi≤109-10^9 \le x_i, y_i \le 10^9
  • 0≤ai<bi≤1090 \le a_i < b_i \le 10^9

Example 1

Input 1
2
0 0 1 2
1 1 1 2
Output 1
250000002
Explanation

The bounding rectangle has area 11 only if both points are selected, which happens with probability 1/41/4. Otherwise the area is 00.

Example 2

Input 2
2
0 0 1 2
3 4 1 2
Output 2
3
Explanation

Both points are selected with probability 1/41/4, and then the area is 1212. The expected area is 33.

Example 3

Input 3
3
0 0 1 2
2 0 1 2
0 2 1 2
Output 3
1
Explanation

Each subset of the three points is equally likely. The only non-degenerate rectangles come from selecting both (2,0)(2, 0) and (0,2)(0, 2) (area 44), and from selecting all three points (area 44). The expected area is therefore 11.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.