Lonely Mountain
Time limit2sMemory limit256 MB
Given two orthogonal mountain silhouettes, decide whether any solid casts both and print the largest possible volume modulo 1000000007.
- Level
Hard9 of 10
- Topics
- Geometry, Math, Sorting, Number theory
- Solved
- No attempts yet
Problem
"This was made by Thror, your grandfather, Thorin", he said in answer to the dwarves' excited questions. "It is a plan of the Mountain."
J. R. R. Tolkien, The Hobbit, or There and Back Again
The plan of the Lonely Mountain is two parallel projections of the mountain onto two projection planes. Both planes are perpendicular to the ground and to each other. Each projection has a mountain-like shape.
Bilbo has never seen the mountain, so he tries to picture it. Is a single mountain really standing there alone, or do ridges and other mountains surround it? Either way it has to be enormous, since it holds the whole kingdom of the dwarves.
Bilbo decided to estimate the largest volume the Lonely Mountain and the mountains around it can occupy, working only from the plan Gandalf gave him.
Put the ground on the plane . The first projection is drawn on the plane and the second one on the plane. A projection given by the points means the region , where is the piecewise linear function running through those points in order.
Among all solids whose parallel projection onto is exactly the first region and whose parallel projection onto is exactly the second region, find the volume of the largest one.
Input
The first line contains one integer , the number of points in the parallel projection of the mountain onto the plane (). The second line contains pairs of integers , the coordinates of the polygonal chain that forms this projection (, , ).
The next two lines contain the projection onto the plane in the same format.
Output
If no solid matches both projections, print Invalid plan.
Otherwise the largest possible volume is a rational number. Write it as an irreducible fraction . Under the constraints above is never a multiple of , so exactly one integer satisfies and . Print that .