Under construction

Still being built. Things may change

Hitting the Targets

Time limit1sMemory limit1024 MB

Summary
Count the shooting orders that hit all N targets, where each shot takes the top or bottom target of one string, modulo 10^9+7.
Level

Medium5 of 10

Topics
Combinatorics, Math
Solved
No attempts yet

Problem

There are NN targets numbered from 11 to NN. The targets hang on MM strings. The ii-th string has A_iA\_i targets hanging on it, and the sum of all A_iA\_i is NN.

Seunghwan wants to hit all NN targets, hitting exactly one target per shot, using NN shots in total. Each time he shoots, he picks one string and hits the topmost or the bottommost target on that string. His arrow is a magic arrow, so a target that is hit disappears. If only one target remains on a string, that target is both the topmost and the bottommost one. If a string has no targets left, he does not pick that string. Count the number of orders in which Seunghwan can shoot the targets.

Input

The first line contains the number of targets NN (1≤N≤5×1061\leq N\leq 5\times 10^6) and the number of strings MM (1≤M≤N1\leq M\leq N).

The second line contains the number of targets hanging on each string, A_1,A_2,⋯ ,A_MA\_1,A\_2,\cdots ,A\_M (1≤A_i≤N1\leq A\_i\leq N; ∑_i=1MA_i=N\sum\_{i=1}^{M}A\_i=N), separated by spaces.

Output

Print the number of orders in which Seunghwan shoots the targets, modulo 109+710^9+7, on the first line.

Note that 109+710^9+7 is a prime number.

Examples1

  1. Example 1

    Input
    10 4
    1 2 3 4
    
    Expected output
    806400