Hitting the Targets
Time limit1sMemory limit1024 MB
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 targets numbered from to . The targets hang on strings. The -th string has targets hanging on it, and the sum of all is .
Seunghwan wants to hit all targets, hitting exactly one target per shot, using 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 () and the number of strings ().
The second line contains the number of targets hanging on each string, (; ), separated by spaces.
Output
Print the number of orders in which Seunghwan shoots the targets, modulo , on the first line.
Note that is a prime number.