This page is still under construction.

Parts of this page are still being built. What you see may change.

Hyperrectangle

Time limit2sMemory limit512 MB

Summary
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 dd-dimensional hyperrectangle of size l1×⋯×ldl_1 \times \cdots \times l_d as a birthday present. Snuke placed it so that its ii-th coordinate lies between 00 and lil_i, and ate the part of the hyperrectangle satisfying x1+⋯+xd≤sx_1 + \cdots + x_d \le s. (Here xix_i denotes the ii-th coordinate.) Let VV be the volume of the part Snuke ate. We can prove that d!Vd!V is always an integer. Compute d!Vd!V modulo 109+710^9 + 7.

Input

The first line contains one integer dd (2≤d≤3002 \le d \le 300). Then dd lines follow; the ii-th of these lines contains one integer lil_i (1≤li≤3001 \le l_i \le 300). The last line contains one integer ss (0≤s≤∑li0 \le s \le \sum l_i).

Output

Print d!Vd!V modulo 109+710^9 + 7.

Hint

Illustration for Sample 1:

Examples2

  1. Example 1

    Input
    2
    6
    3
    4
    
    Expected output
    15
    
  2. Example 2

    Input
    5
    12
    34
    56
    78
    90
    123
    
    Expected output
    433127538