Hyperrectangle
Time limit2sMemory limit512 MB
Compute d!V for the volume of a box with side lengths li where sum xi <= s via characteristic polynomials and Lenstra inclusion of capped orthants.
- Level
Hard10 of 10
- Topics
- Math, Divide and conquer, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
Snuke received a -dimensional hyperrectangle of size as a birthday present. Snuke placed it so that its -th coordinate lies between and , and ate the part of the hyperrectangle satisfying . (Here denotes the -th coordinate.) Let be the volume of the part Snuke ate. We can prove that is always an integer. Compute modulo .
Input
The first line contains one integer (). Then lines follow; the -th of these lines contains one integer (). The last line contains one integer ().
Output
Print modulo .
Hint
Illustration for Sample 1:
