#P11011. 「ALFR Round 4」A 点的覆盖

「ALFR Round 4」A 点的覆盖

Problem Description

In the 2D Cartesian coordinate system, if both the xx-coordinate and the yy-coordinate of a point are integers, we call it an integer point. Given a rectangle AA whose vertices are all integer points and whose sides are parallel to the coordinate axes, and given nn integer points p1,p2,p3,,pnp_1, p_2, p_3, \cdots, p_n inside rectangle AA (possibly on its boundary), ask how many sub-rectangles of AA satisfy:

  • All vertices are integer points.

  • All four sides are parallel to a coordinate axis.

  • They can completely cover (boundary is allowed) p1,p2,p3,,pnp_1, p_2, p_3, \cdots, p_n.

In this problem, the length or width of a rectangle may be 00.

Input Format

The first line contains five integers, which are the number of given integer points nn, the xx-coordinate of the upper-left vertex of rectangle AA, the yy-coordinate of the upper-left vertex, the xx-coordinate of the lower-right vertex, and the yy-coordinate of the lower-right vertex.

Lines 22 to n+1n+1: in line ii, two integers give the xx-coordinate and yy-coordinate of pi1p_{i-1}.

Output Format

Output one integer in one line, representing the answer modulo 109+710^9+7.

3 1 5 6 1
2 3
2 4
4 2
24

Hint

Subtask Score Constraints
00 2020 n102n \le 10^2, the coordinates of all points are less than 10210^2
11 All points except the vertices of AA have the same xx-coordinate
22 6060 -

For 100%100\% of the testdata, 1n1061 \le n \le 10^6, all point coordinates are positive integers and less than 10910^9.

Translated by ChatGPT 5