Fence
Time limit3sMemory limit512 MB
Sum x! times y! over all unit cells inside an axis-aligned polygon, modulo 1e9+7, with coordinates up to 1e9.
- Level
Hard8 of 10
- Topics
- Math, Prefix sum, Geometry, Number theory
- Solved
- No attempts yet
Problem
A pasture where factorials grow lies in the standard coordinate system, where the coordinate increases to the right and the coordinate increases upward. A cell is a square with side length 1 and sides parallel to the coordinate axes, such that both coordinates of its lower left corner are nonnegative integers. The value of such a cell is , where for and .
A fence is a polygon whose sides are parallel to the coordinate axes. Given a fence, compute the sum of the values of all cells inside the fence, modulo .
Input
The first line contains a positive integer (), the number of vertices of the fence.
The -th of the next lines contains integers and (), the coordinates of the -th vertex of the fence. The vertices are listed in order along the polygon.
You may assume that the vertices form a polygon whose sides are parallel to the coordinate axes. In particular, the polygon does not intersect itself, and two adjacent sides are never parallel.
Output
Print the requested sum modulo on the first line.
Hint
The figure shows the fence from the third example and the value of each cell. The values of the cells inside the fence add up to 119.
