Expected Bounding Box (Stretch)
View as PDFThis is a stretch problem.
There are points on the plane. Point
has coordinates
and is selected
independently with probability
.
Let be the random set of selected points, and let
be the smallest axis-aligned
bounding rectangle containing every point of
. The geometric area of
is
.
If has fewer than two points, or all selected points share the same
-coordinate or
the same
-coordinate, this area is
.
Output the expected area of .
It can be shown that the answer can be expressed as a rational number in lowest
terms with
coprime to
. Output
.
Input
The first line contains an integer .
Each of the next lines contains four integers
,
,
, and
.
Output
Print a single integer: the expected area modulo .
Constraints
Example 1
Input
2
0 0 1 2
1 1 1 2
Output
250000002
Explanation
The bounding rectangle has area only if both points are selected, which happens with
probability
. Otherwise the area is
.
Example 2
Input
2
0 0 1 2
3 4 1 2
Output
3
Explanation
Both points are selected with probability , and then the area is
. The expected
area is
.
Example 3
Input
3
0 0 1 2
2 0 1 2
0 2 1 2
Output
1
Explanation
Each subset of the three points is equally likely. The only non-degenerate rectangles come
from selecting both and
(area
), and from selecting all three points
(area
). The expected area is therefore
.
Comments