Sum x! times y! over all unit cells inside an axis-aligned polygon, modulo 1e9+7, with coordinates up to 1e9.
Hard8MathPrefix sumGeometryNumber theoryNo attempts yetTime limit3sMemory limit512 MBA pasture where factorials grow lies in the standard coordinate system, where the x coordinate increases to the right and the y 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 A=(xA,yA) are nonnegative integers. The value of such a cell is xA!×yA!, where a!=1×2×⋯×a for a≥1 and 0!=1.
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 109+7.
The first line contains a positive integer n (n≤100), the number of vertices of the fence.
The k-th of the next n lines contains integers xk and yk (0≤xk,yk≤109), the coordinates of the k-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.
Print the requested sum modulo 109+7 on the first line.
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.
