We have a sequence A of N non-negative integers.
Compute the sum of \prod _{i = 1} ^N \dbinom{B_i}{A_i} over all sequences B of N non-negative integers whose sum is at most M, and print it modulo (10^9 + 7).
Here, \dbinom{B_i}{A_i}, the binomial coefficient, denotes the number of ways to choose A_i objects from B_i objects, and is 0 when B_i < A_i.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 2000
 - 1 \leq M \leq 10^9
 - 0 \leq A_i \leq 2000

-----Input-----
Input is given from Standard Input in the following format:
N M
A_1 A_2 \ldots A_N

-----Output-----
Print the sum of \prod _{i = 1} ^N \dbinom{B_i}{A_i}, modulo (10^9 + 7).

-----Sample Input-----
3 5
1 2 1

-----Sample Output-----
8

There are four sequences B such that \prod _{i = 1} ^N \dbinom{B_i}{A_i} is at least 1:
 - B = \{1, 2, 1\}, where \prod _{i = 1} ^N \dbinom{B_i}{A_i} = \dbinom{1}{1} \times \dbinom{2}{2} \times \dbinom{1}{1} = 1;
 - B = \{2, 2, 1\}, where \prod _{i = 1} ^N \dbinom{B_i}{A_i} = \dbinom{2}{1} \times \dbinom{2}{2} \times \dbinom{1}{1} = 2;
 - B = \{1, 3, 1\}, where \prod _{i = 1} ^N \dbinom{B_i}{A_i} = \dbinom{1}{1} \times \dbinom{3}{2} \times \dbinom{1}{1} = 3;
 - B = \{1, 2, 2\}, where \prod _{i = 1} ^N \dbinom{B_i}{A_i} = \dbinom{1}{1} \times \dbinom{2}{2} \times \dbinom{2}{1} = 2.
The sum of these is 1 + 2 + 3 + 2 = 8.

Difficulty: HARD

Starter code:

Solutions:
from functools import reduce

def modpow(a, n, m):
	if n == 0:
		return 1
	tmp = modpow(a, n // 2, m)
	if n % 2 == 0:
		return tmp * tmp % m
	else:
		return tmp * tmp * a % m

def modinv(a, m):
	return modpow(a, m - 2, m)
(n, m) = [int(_) for _ in input().split(' ')]
s = sum([int(_) for _ in input().split(' ')])
M = 1000000007
product = lambda x1, x2: x1 * x2 % M
print(reduce(product, list(range(m - s + 1, m + n + 1))) * modinv(reduce(product, list(range(1, s + n + 1))), M) % M)


(n, m, *a) = map(int, open(0).read().split())
d = 10 ** 9 + 7
l = 1
r = 1
for i in range(n + sum(a)):
	(l, r) = (l * (n + m - i) % d, r * (i + 1) % d)
print(l * pow(r, d - 2, d) % d)


def mod_combination(n, k, mod=10 ** 9 + 7):

	def extended_gcd(a, b):
		if b == 0:
			return (a, 1, 0)
		(d, x, y) = extended_gcd(b, a % b)
		return (d, y, x - a // b * y)
	(p, q) = (1, 1)
	for i in range(n - k + 1, n + 1):
		p = p * i % mod
	for i in range(2, k + 1):
		q = q * i % mod
	return p * (extended_gcd(q, mod)[1] % mod) % mod
(N, M, *A) = map(int, open(0).read().split())
S = sum(A)
print(mod_combination(M + N, S + N))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
s = sum(a)
fact = 1
ans = 1
for i in range(s + n):
	ans *= m + n - i
	ans %= mod
	fact *= i + 1
	fact %= mod
ans *= pow(fact, mod - 2, mod)
print(ans % mod)


import itertools
(N, M, *A) = [int(_) for _ in open(0).read().split()]

class Factorial:

	def __init__(self, max_fact, mod):
		f = [1] * (max_fact + 1)
		for idx in range(2, max_fact + 1):
			f[idx] = f[idx - 1] * idx
			f[idx] %= mod
		if mod > max_fact:
			fi = [pow(f[-1], mod - 2, mod)]
			for idx in range(max_fact, 0, -1):
				fi += [fi[-1] * idx % mod]
			fi = fi[::-1]
		else:
			fi = [pow(n, mod - 2, mod) for n in f]
		self.mod = mod
		self.f = f
		self.fi = fi

	def factorial(self, n):
		return self.f[n]

	def factorial_inverse(self, n):
		return self.fi[n]

	def combination(self, n, r):
		if n < r:
			return 0
		elif n < 2 * r:
			r = n - r
		f = self.f
		fi = self.fi
		mod = self.mod
		if n < len(f):
			return f[n] * fi[r] * fi[n - r] % mod
		if r < len(f):
			ret = fi[r]
			for _ in range(r):
				ret *= n
				ret %= mod
				n -= 1
			return ret
		else:
			1 / 0

	def permutation(self, n, r):
		f = self.f
		fi = self.fi
		mod = self.mod
		if n < len(f):
			return f[n] * fi[n - r] % mod
		elif r < len(f):
			ret = 1
			for _ in range(r):
				ret *= n
				ret %= mod
				n -= 1
			return ret
		else:
			1 / 0

	def homogeneous_product(self, n, r):
		f = self.f
		fi = self.fi
		return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod
suma = sum(A)
max_fact = suma + N
mod = 10 ** 9 + 7
fact_instance = Factorial(max_fact, mod)
comb = fact_instance.combination
ans = comb(M + N, N + suma)
print(ans)


import sys
input = sys.stdin.readline
(N, M) = list(map(int, input().split()))
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
SUM = sum(A)
r = M - SUM
S = r + SUM + N
F = 1
for i in range(1, S - r + 1):
	F = F * i % mod
if M < SUM:
	print(0)
else:
	ANS = 1
	y = 1
	for i in range(S - r):
		ANS = ANS * S % mod
		S -= 1
	ANS = ANS * pow(F, mod - 2, mod) % mod
	print(ANS)


import sys
input = sys.stdin.readline
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, accumulate
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
SI = lambda : input()
NI = lambda : int(input())
MI = lambda : map(int, input().split())
cutLF = lambda x: list(x)[:-1] if x[-1] == '\n' else list(x)
strLST = lambda : cutLF(input())
(n, m) = MI()
(*a,) = MI()
s = sum(a)
mod = 10 ** 9 + 7
hidari = []
start = n + m
for i in range(n + s):
	hidari.append(start - i)
left = 1
right = 1
for i in range(n + s):
	left *= hidari[i]
	left %= mod
	right *= i + 1
	right %= mod
print(left * pow(right, mod - 2, mod) % mod)


import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline

def modInverse(a, p):
	return pow(a, p - 2, p)

def modBinomial(n, k, p):
	k = min(k, n - k)
	numerator = 1
	for i in range(k):
		numerator = numerator * (n - i) % p
	denominator = 1
	for i in range(1, k + 1):
		denominator = denominator * i % p
	return numerator * modInverse(denominator, p) % p

def main():
	(N, M) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	MOD = 10 ** 9 + 7
	if sum(A) > M:
		print(0)
		return
	r = sum(A) + N
	print(modBinomial(M + N, r, MOD))

def __starting_point():
	main()
__starting_point()


P = 10 ** 9 + 7
(N, M) = map(int, input().split())
A = [int(a) for a in input().split()]
s = sum(A)
u = 1
v = 1
for i in range(M - s + 1, N + M + 1):
	u = u * i % P
for i in range(1, s + N + 1):
	v = i * v % P
print(u * pow(v, P - 2, P) % P)


k = 72
kk = k // 4
K = 1 << k
nu = lambda L: int(''.join([hex(K + a)[3:] for a in L[::-1]]), 16)
st = lambda n: hex(n)[2:]
li = lambda s, l, r: [int(a, 16) % P if len(a) else 0 for a in [s[-(i + 1) * kk:-i * kk] for i in range(l, r)]]

def grow(d, v, h, start):
	h += [0] * d
	f = [(-1 if (i + d) % 2 else 1) * fainv[i] * fainv[d - i] % P * h[i] % P for i in range(d + 1)]
	nuf = nu(f)
	a = d * inv[v] % P
	t = [1] * (3 * d + 3)
	for i in range(1, 3 * d + 3):
		t[i] = t[i - 1] * (a - d + i - 1) % P
	ti = [1] * (3 * d + 3)
	ti[-1] = pow(t[-1], P - 2, P)
	for i in range(1, 3 * d + 3)[::-1]:
		ti[i - 1] = ti[i] * (a - d + i - 1) % P
	iv = [1] * (3 * d + 3)
	for i in range(1, 3 * d + 3):
		iv[i] = ti[i] * t[i - 1] % P
	g = iv[1:2 * d + 2]
	fg = li(st(nuf * nu(g)), d, d * 2 + 1)
	for i in range(d + 1):
		h[i] = h[i] * (fg[i] * t[d + i + 1] % P * ti[i] % P) % P
	g = inv[1:2 * d + 2]
	fg = li(st(nuf * nu(g)), d, d * 2 + 1)
	for i in range(d):
		h[i + d + 1] = fg[i] * fa[d + i + 1] % P * fainv[i] % P
	g = iv[d + 2:3 * d + 3]
	fg = li(st(nuf * nu(g)), d, d * 2 + 1)
	for i in range(d):
		h[i + d + 1] = h[i + d + 1] * (fg[i] * t[2 * d + i + 2] % P * ti[d + i + 1] % P) % P
	return h

def create_table(v, start):
	s = 1
	X = [start, v + start]
	while s < v:
		X = grow(s, v, X, start)
		s *= 2
	table = [1]
	for x in X:
		table.append(table[-1] * x % P)
	return table

def fact(i, table):
	a = table[i // v]
	for j in range(i // v * v + 1, i + 1):
		a = a * j % P
	return a
P = 10 ** 9 + 7
nn = 4000000
v = 1 << (nn.bit_length() + 1) // 2
fa = [1] * (2 * v + 2)
fainv = [1] * (2 * v + 2)
for i in range(2 * v + 1):
	fa[i + 1] = fa[i] * (i + 1) % P
fainv[-1] = pow(fa[-1], P - 2, P)
for i in range(2 * v + 1)[::-1]:
	fainv[i] = fainv[i + 1] * (i + 1) % P
inv = [0] * (2 * v + 2)
for i in range(1, 2 * v + 2):
	inv[i] = fainv[i] * fa[i - 1] % P

def prod(a, b, v):
	T = create_table(v, a)
	c = b - a
	s = T[c // v]
	if c > 10:
		vv = 1 << (c.bit_length() + 1) // 2
		return s * prod(c // v * v + a, b, vv) % P
	for i in range(c // v * v + a, b):
		s = s * i % P
	return s

def C(a, b):
	if b * 2 > a:
		b = a - b
	return prod(a - b + 1, a + 1, v) * pow(prod(1, b + 1, v), P - 2, P) % P
if 1:
	(N, M) = list(map(int, input().split()))
	A = [int(a) for a in input().split()]
	s = sum(A)
	print(C(N + M, s + N) if M >= s else 0)


import bisect
import functools
import heapq
import itertools
import sys
import math
import random
import time
from collections import Counter, deque, defaultdict
from functools import reduce
from operator import xor, itemgetter
from pprint import pprint
from types import FunctionType
from typing import List, Any
from sys import stdin
mod = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 9)

def inp():
	return stdin.readline().rstrip()

def lmi():
	return list(map(int, stdin.readline().split()))

def narray(*shape, init: Any=0):
	if shape:
		return [narray(*shape[1:], init=init) for _ in range(shape[0])]
	if callable(init):
		return init()
	return init

def comb(N, k):
	if k > N or N < 0 or k < 0:
		return 0
	(N, k) = list(map(int, (N, k)))
	top = N
	val = 1
	while top > N - k:
		val *= top
		top -= 1
	n = 1
	while n < k + 1:
		val //= n
		n += 1
	return val

def cmb(x, y):
	if x < y:
		return 0
	bunsi = 1
	bunbo = 1
	for i in range(1, y + 1):
		bunsi = bunsi * (x + 1 - i) % mod
		bunbo = bunbo * i % mod
	res = bunsi * pow(bunbo, mod - 2, mod) % mod
	return res

def main():
	(N, M) = lmi()
	A = lmi()
	ans = cmb((M + N) % mod, (N + sum(A)) % mod) % mod
	print(ans)

def __starting_point():
	main()
__starting_point()


def binomial_coefficient(n, r, mod=10 ** 9 + 7):
	if r < 0 or r > n:
		return 0
	res = 1
	div = 1
	r = min(r, n - r)
	for i in range(r):
		res = res * (n - i) % mod
		div = div * (i + 1) % mod
	return res * pow(div, mod - 2, mod) % mod
mod = 10 ** 9 + 7
(n, m) = map(int, input().split())
A = list(map(int, input().split()))
ans = binomial_coefficient(n + m, sum(A) + n, mod)
print(ans)


import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate
sys.setrecursionlimit(10 ** 6)
INF = 10 ** 12
p = 10 ** 9 + 7

def main():
	(N, M) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	S = sum(A)
	if M < S:
		print(0)
		return
	ans = 1
	div = 1
	for i in range(N + S):
		ans *= M + N - i
		div *= N + S - i
		ans %= p
		div %= p
	print(ans * pow(div, p - 2, p) % p)

def __starting_point():
	main()
__starting_point()


import sys

def input():
	return sys.stdin.readline().strip()

def mapint():
	return map(int, input().split())
sys.setrecursionlimit(10 ** 9)
(N, M) = mapint()
As = list(mapint())
mod = 10 ** 9 + 7
SUM = sum(As)
ans = 1
for i in range(M - SUM + 1, M + N + 1):
	ans *= i
	ans %= mod
inv = 1
for i in range(1, SUM + N + 1):
	inv *= i
	inv %= mod
print(ans * pow(inv, mod - 2, mod) % mod)


(N, M) = map(int, input().split())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
invs = [0, 1]
X = N + M
Y = N + sum(A)

def inv(x):
	if x == 1:
		return 1
	else:
		return -invs[mod % x] * (mod // x) % mod
for i in range(2, Y + 1):
	invs.append(inv(i))
ans = 1
for i in range(Y):
	ans *= (X - i) * invs[i + 1]
	ans %= mod
print(ans % mod)


import sys

class IO:

	@staticmethod
	def get(type=str):
		return type(input().strip())

	@staticmethod
	def gets(type=str):
		return [type(x) for x in input().split()]

def printerr(*args, **kw):
	print(*args, **kw, file=sys.stderr)

def inv(n, p):
	return pow(n, p - 2, p)

def comb(n, k, p):
	k = min(k, n - k)
	(t, d) = (1, 1)
	for i in range(k):
		t *= n - i
		t %= P
		d *= i + 1
		d %= P
	return t * inv(d, P) % P
P = 10 ** 9 + 7

def main():
	(n, m) = IO.gets(int)
	a = IO.gets(int)
	x = sum(a) + n
	dm = m - sum(a)
	printerr(f'x={x} dm={dm}')
	if dm < 0:
		ans = 0
	elif dm == 0:
		ans = 1
	else:
		ans = comb(x + dm, dm, P)
	print(ans)

def __starting_point():
	main()
__starting_point()


k = 72
kk = k // 4
K = 1 << k

def nu(L, sl=-1):
	if sl == -1:
		sl = slice(0, len(L))
	return int(''.join([hex(K + a)[3:] for a in L[sl][::-1]]), 16)
st = lambda n: hex(n)[2:]
li = lambda s, l, r: [int(a, 16) % P if len(a) else 0 for a in [s[-(i + 1) * kk:-i * kk] for i in range(l, r)]]

def grow(d, v, h, start):
	h += [0] * d
	f = [(-1 if (i + d) % 2 else 1) * fainv[i] * fainv[d - i] % P * h[i] % P for i in range(d + 1)]
	nuf = nu(f)
	a = d * inv[v] % P
	t = [1] * (3 * d + 3)
	for i in range(1, 3 * d + 3):
		t[i] = t[i - 1] * (a - d + i - 1) % P
	ti = [1] * (3 * d + 3)
	ti[-1] = pow(t[-1], P - 2, P)
	for i in range(1, 3 * d + 3)[::-1]:
		ti[i - 1] = ti[i] * (a - d + i - 1) % P
	iv = [1] * (3 * d + 3)
	for i in range(1, 3 * d + 3):
		iv[i] = ti[i] * t[i - 1] % P
	fg = li(st(nuf * nu(iv[1:2 * d + 2])), d, d * 2 + 1)
	for (i, (_fg, _ti)) in enumerate(zip(fg, ti)):
		h[i] = h[i] * (_fg * t[d + i + 1] % P * _ti % P) % P
	fg1 = li(st(nuf * nu(inv[1:2 * d + 2])), d, d * 2 + 1)
	fg2 = li(st(nuf * nu(iv[d + 2:3 * d + 3])), d, d * 2 + 1)
	fg1.pop()
	for (i, (_fg1, _fg2)) in enumerate(zip(fg1, fg2)):
		h[i + d + 1] = _fg1 * _fg2 % P * fa[d + i + 1] % P * fainv[i] % P * t[2 * d + i + 2] % P * ti[d + i + 1] % P
	return h

def create_table(v, start=1):
	s = 1
	X = [start, v + start]
	while s < v:
		X = grow(s, v, X, start)
		s *= 2
	table = [1]
	for x in X:
		table.append(table[-1] * x % P)
	return table
P = 10 ** 9 + 7
nn = 4000000
v = 1 << (nn.bit_length() + 1) // 2
fa = [1] * (2 * v + 2)
fainv = [1] * (2 * v + 2)
for i in range(2 * v + 1):
	fa[i + 1] = fa[i] * (i + 1) % P
fainv[-1] = pow(fa[-1], P - 2, P)
for i in range(2 * v + 1)[::-1]:
	fainv[i] = fainv[i + 1] * (i + 1) % P
inv = [0] * (2 * v + 2)
for i in range(1, 2 * v + 2):
	inv[i] = fainv[i] * fa[i - 1] % P

def prod(a, b, vv):
	T = create_table(vv, a)
	c = b - a
	s = T[c // vv]
	for i in range(c // vv * vv + a, b):
		s = s * i % P
	return s

def C(a, b):
	if not 0 <= b <= a:
		return 0
	if b * 2 > a:
		b = a - b
	return prod(a - b + 1, a + 1, v) * pow(prod(1, b + 1, v), P - 2, P) % P
(N, M) = map(int, input().split())
s = sum([int(a) for a in input().split()])
print(C(N + M, s + N))


import sys

def solve():
	input = sys.stdin.readline
	(N, M) = map(int, input().split())
	A = [int(a) for a in input().split()]
	if M < sum(A):
		print(0)
		return 0
	mod = 7 + 10 ** 9
	Ans = 1
	sumA = sum(A)
	for i in range(sumA + N):
		Ans *= M + N - i
		Ans %= mod
	fact = 1
	for i in range(1, sumA + N + 1):
		fact *= i
		fact %= mod
	Ans *= pow(fact, mod - 2, mod)
	print(Ans % mod)
	return 0

def __starting_point():
	solve()
__starting_point()


M = lambda : map(int, input().split())
(n, m) = M()
a = sum(list(M()))
d = 10 ** 9 + 7
l = 1
r = 1
for i in range(n + a):
	(l, r) = (l * (n + m - i) % d, r * (i + 1) % d)
print(l * pow(r, d - 2, d) % d)


import sys
sys.setrecursionlimit(10 ** 7)

def I():
	return int(sys.stdin.readline().rstrip())

def MI():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def LI2():
	return list(map(int, sys.stdin.readline().rstrip()))

def S():
	return sys.stdin.readline().rstrip()

def LS():
	return list(sys.stdin.readline().rstrip().split())

def LS2():
	return list(sys.stdin.readline().rstrip())
(N, M) = MI()
A = LI()
s = sum(A)
mod = 10 ** 9 + 7
if s > M:
	print(0)
	return
a = 1
for i in range(1, s + N + 1):
	a *= i
	a %= mod
ans = pow(a, mod - 2, mod)
for i in range(s + N):
	ans *= M + N - i
	ans %= mod
print(ans)


from functools import reduce

def combination2(n, r, MOD=10 ** 9 + 7):
	if not 0 <= r <= n:
		return 0
	r = min(r, n - r)
	numerator = reduce(lambda x, y: x * y % MOD, range(n, n - r, -1), 1)
	denominator = reduce(lambda x, y: x * y % MOD, range(1, r + 1), 1)
	return numerator * pow(denominator, MOD - 2, MOD) % MOD
(N, M) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
print(combination2(M + N, S + N))


import sys

def input():
	return sys.stdin.readline().rstrip()

def permutation(n, r, mod=10 ** 9 + 7):
	permutation = 1
	for i in range(r):
		permutation = permutation * (n - i) % mod
	return permutation

def combination(n, r, mod=10 ** 9 + 7):
	r = min(n - r, r)
	bunshi = permutation(n, r, mod)
	bunbo = 1
	for i in range(1, r + 1):
		bunbo = bunbo * i % mod
	return bunshi * pow(bunbo, mod - 2, mod) % mod

def main():
	mod = 10 ** 9 + 7
	mod2 = 998244353
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	ans = 1
	for AA in A:
		ans *= AA
		ans %= mod
	sumA = sum(A)
	if sumA > m:
		print(0)
	else:
		nokori = m - sum(A)
		print(combination(m + n, sumA + n, mod=10 ** 9 + 7))

def __starting_point():
	main()
__starting_point()


def comb(n, r, mod):
	(x, y) = (1, 1)
	for i in range(n, n - r, -1):
		x *= i
		y *= i + r - n
		x %= mod
		y %= mod
	return pow(y, mod - 2, mod) * x % mod
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
mod = pow(10, 9) + 7
ans = comb(n + m, n + sum(a), mod)
print(ans)


import sys
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians
sys.setrecursionlimit(10 ** 6)
INF = 10 ** 20
eps = 1e-20
MOD = 10 ** 9 + 7

def lcm(x, y):
	return x * y // gcd(x, y)

def lgcd(l):
	return reduce(gcd, l)

def llcm(l):
	return reduce(lcm, l)

def powmod(n, i, mod=MOD):
	return pow(n, mod - 1 + i, mod) if i < 0 else pow(n, i, mod)

def div2(x):
	return x.bit_length()

def div10(x):
	return len(str(x)) - (x == 0)

def intput():
	return int(input())

def mint():
	return map(int, input().split())

def lint():
	return list(map(int, input().split()))

def ilint():
	return (int(input()), list(map(int, input().split())))

def judge(x, l=['Yes', 'No']):
	print(l[0] if x else l[1])

def lprint(l, sep='\n'):
	for x in l:
		print(x, end=sep)

def ston(c, c0='a'):
	return ord(c) - ord(c0)

def ntos(x, c0='a'):
	return chr(x + ord(c0))

class counter(dict):

	def __init__(self, *args):
		super().__init__(args)

	def add(self, x, d=1):
		self.setdefault(x, 0)
		self[x] += d

	def list(self):
		l = []
		for k in self:
			l.extend([k] * self[k])
		return l

class comb:

	def __init__(self, n, mod=None):
		self.l = [1]
		self.n = n
		self.mod = mod

	def get(self, k):
		(l, n, mod) = (self.l, self.n, self.mod)
		if k < 0 or n < k:
			return 0
		k = n - k if k > n // 2 else k
		while len(l) <= k:
			i = len(l)
			l.append(l[i - 1] * (n + 1 - i) // i if mod == None else l[i - 1] * (n + 1 - i) * powmod(i, -1, mod) % mod)
		return l[k]

def pf(x, mode='counter'):
	C = counter()
	p = 2
	while x > 1:
		k = 0
		while x % p == 0:
			x //= p
			k += 1
		if k > 0:
			C.add(p, k)
		p = p + 2 - (p == 2) if p * p < x else x
	if mode == 'counter':
		return C
	S = set([1])
	for k in C:
		T = deepcopy(S)
		for x in T:
			for i in range(1, C[k] + 1):
				S.add(x * k ** i)
	if mode == 'set':
		return S
	if mode == 'list':
		return sorted(list(S))

def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
mod = 10 ** 9 + 7
N = 10 ** 4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
(N, M) = mint()
A = lint()
S = sum(A)
if S > M:
	print(0)
	return
n = S + N + M - S
k = S + N
mod = 10 ** 9 + 7
modinv_table = [-1] * (k + 1)
modinv_table[1] = 1
for i in range(2, k + 1):
	modinv_table[i] = -modinv_table[mod % i] * (mod // i) % mod

def binomial_coefficients(n, k):
	ans = 1
	for i in range(k):
		ans *= n - i
		ans *= modinv_table[i + 1]
		ans %= mod
	return ans
print(binomial_coefficients(n, k))


(N, M) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
MOD = 10 ** 9 + 7

def comb(n, r):
	ans = div = 1
	for i in range(r):
		ans = ans * (n - i) % MOD
		div = div * (i + 1) % MOD
	ans = ans * pow(div, MOD - 2, MOD) % MOD
	return ans
ans = comb(N + M, S + N)
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
inv = [0, 1]
for i in range(2, 5 * 10 ** 6):
	inv += [inv[mod % i] * (mod - int(mod / i)) % mod]
s = sum(a)
ans = 1
for i in range(n + s):
	ans *= n + m - i
	ans %= mod
	ans *= inv[i + 1]
	ans %= mod
print(ans)


(N, M) = map(int, input().split())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

def binomial_coefficients(n, k):
	numera = 1
	denomi = 1
	for i in range(k):
		numera *= n - i
		numera %= mod
		denomi *= i + 1
		denomi %= mod
	return numera * pow(denomi, -1, mod) % mod
print(binomial_coefficients(M + N, N + sum(A)))


(n, m) = list(map(int, input().split()))
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
s = sum(A)
ans = 1

def comb(n, r, mod):
	c = 1
	for i in range(r):
		c *= n - i
		c %= mod
	d = 1
	for i in range(1, r + 1):
		d *= i
		d %= mod
	return c * pow(d, mod - 2, mod) % mod
print(comb(m + n, s + n, mod))


(N, M) = list(map(int, input().split()))
A = list(map(int, input().split()))
S = sum(A)
MOD = 10 ** 9 + 7
a = b = 1
for i in range(1, S + N + 1):
	a *= M + N + 1 - i
	a %= MOD
	b *= i
	b %= MOD
ans = a * pow(b, MOD - 2, MOD)
ans %= MOD
print(ans)


MOD = 10 ** 9 + 7
(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
r = n + sum(a)
m += n
if m < r:
	print(0)
else:
	ans = 1
	v = 1
	for i in range(r):
		v *= i + 1
		ans *= m - i
		v %= MOD
		ans %= MOD
	print(ans * pow(v, MOD - 2, MOD) % MOD)


class Factorials:

	def __init__(self, n=10 ** 6, mod=10 ** 9 + 7):
		self.mod = mod
		self.fac = [1] * (n + 1)
		for i in range(2, n + 1):
			self.fac[i] = self.fac[i - 1] * i % mod
mod = 10 ** 9 + 7

def fact(n, r):
	res = 1
	for i in range(r):
		res *= n - i
		res %= mod
	return res
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
sum_a = sum(a)
if m < sum_a:
	print(0)
	return
fct = Factorials(sum_a + n)
print(fact(n + m, sum_a + n) * pow(fct.fac[sum_a + n], mod - 2, mod) % mod)


mod = 10 ** 9 + 7
(n, m) = map(int, input().split())
s = sum(map(int, input().split()))
a = n + m
b = s + n
num = 1
den = 1
for i in range(b):
	num *= a - i
	num %= mod
	den *= i + 1
	den %= mod
ans = num * pow(den, mod - 2, mod) % mod
print(ans)


import sys
input = sys.stdin.readline
(N, M) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mod = 10 ** 9 + 7
dsm = M - sum(a)
if dsm < 0:
	print(0)
	return

class Factorial:

	def __init__(self, n, mod):
		self.mod = mod
		self.f = [1]
		for i in range(1, n + 1):
			self.f.append(self.f[-1] * i % mod)
		self.i = [pow(self.f[-1], mod - 2, mod)]
		for i in range(1, n + 1)[::-1]:
			self.i.append(self.i[-1] * i % mod)
		self.i.reverse()

	def factorial(self, i):
		return self.f[i]

	def ifactorial(self, i):
		return self.i[i]

	def combi(self, n, k):
		return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod

	def permi(self, n, k):
		return self.f[n] * self.i[n - k] % self.mod
sm = sum(a)
res = Factorial(sm + N, mod).ifactorial(sm + N)
for x in range(N + M, N + M - sm - N, -1):
	res *= x
	res %= mod
print(res)


(N, M) = map(int, input().split())
s = sum(list(map(int, input().split())))
p = 10 ** 9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, s + N + 1):
	fact.append(fact[-1] * i % p)
	inv.append(-inv[p % i] * (p // i) % p)
	factinv.append(factinv[-1] * inv[-1] % p)
ans = factinv[s + N]
for i in range(s + N):
	ans *= M + N - i
	ans %= p
print(ans)


from numba import njit
(N, M, *A) = [int(_) for _ in open(0).read().split()]
mod = 10 ** 9 + 7
suma = sum(A)
x = M + N
y = N + suma
a = 1
b = 1

@njit('i8(i8,i8,i8)')
def pow_mod(base, exp, mod):
	exp %= mod - 1
	res = 1
	while exp:
		if exp & 1:
			res = res * base % mod
		base = base * base % mod
		exp >>= 1
	return res

@njit('i8(i8,i8)')
def comb(x, y):
	a = b = 1
	for _ in range(y):
		a *= x
		b *= y
		a %= mod
		b %= mod
		x -= 1
		y -= 1
	ret = a * pow_mod(b, mod - 2, mod) % mod
	return ret
print(comb(M + N, N + suma))


import sys
MOD = 10 ** 9 + 7
(N, M) = list(map(int, sys.stdin.readline().rstrip().split()))
A = [int(x) for x in sys.stdin.readline().rstrip().split()]

def solve(N, M, A):
	S = sum(A)
	num = 1
	don = 1
	for i in range(1, S + N + 1):
		num = num * (M + N - (i - 1)) % MOD
		don = don * i % MOD
	ans = num * pow(don, MOD - 2, MOD) % MOD
	print(ans)
solve(N, M, A)


MOD = 10 ** 9 + 7
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
ans = 1
den = 1
for i in range(s + n):
	ans *= m + n - i
	ans %= MOD
	den *= i + 1
	den %= MOD
ans = ans * pow(den, MOD - 2, MOD) % MOD
print(ans)


def nCr(n, r):
	A = B = 1
	for _ in range(r):
		A *= n
		A %= Mod
		B *= r
		B %= Mod
		n -= 1
		r -= 1
	return A * pow(B, Mod - 2, Mod) % Mod
(N, M) = map(int, input().split())
A = list(map(int, input().split()))
Mod = 10 ** 9 + 7
print(nCr(M + N, sum(A) + N))


MOD = 10 ** 9 + 7

def COM(n, r):
	(P, Q) = (1, 1)
	for i in range(r):
		P = P * (n - i) % MOD
		Q = Q * (r - i) % MOD
	return P * pow(Q, MOD - 2, MOD) % MOD
(N, M) = map(int, input().split())
S = sum(list(map(int, input().split())))
print(COM(N + M, S + N))


def cmb(x, y):
	if x < y:
		return 0
	bunsi = 1
	bunbo = 1
	for i in range(1, y + 1):
		bunsi = bunsi * (x + 1 - i) % mod
		bunbo = bunbo * i % mod
	res = bunsi * pow(bunbo, mod - 2, mod) % mod
	return res
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
s = sum(a)
ans = cmb(m + n, s + n)
print(ans)


(n, m) = list(map(int, input().split()))
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
s = sum(A)
if s > m:
	print(0)
	return
ans = 1
a = 1
for i in range(n + s):
	ans *= m + n - i
	a *= i + 1
	ans %= mod
	a %= mod
ans = ans * pow(a, mod - 2, mod)
print(ans % mod)


def solve():
	mod = 10 ** 9 + 7
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	M += N
	S = sum(A) + N
	if S > M:
		print(0)
		return
	ans = 1
	d = 1
	for i in range(1, S + 1):
		ans = ans * (M + 1 - i) % mod
		d = d * i % mod
	ans = ans * pow(d, mod - 2, mod) % mod
	print(ans)

def __starting_point():
	solve()
__starting_point()


(N, M) = list(map(int, input().split()))
A = list(map(int, input().split()))
(X, Y) = (M + N, sum(A) + N)
p = 10 ** 9 + 7

def nCr(n, r, mod=p):
	(a, b) = (1, 1)
	for i in range(r):
		a *= n - i
		a %= mod
		b *= i + 1
		b %= mod
	return a * pow(b, mod - 2, mod) % mod
print(nCr(X, Y, p))


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10 ** 9 + 7
inf = float('inf')

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))
(n, m) = LI()
a = LI()
s = sum(a)
if m + n < s + n:
	print(0)
else:
	ans = 1
	inv = 1
	for i in range(s + n):
		ans *= m + n - i
		ans %= mod
		inv *= i + 1
		inv %= mod
	print(ans * pow(inv, mod - 2, mod) % mod)


import sys

def input():
	return sys.stdin.readline()[:-1]

def N():
	return int(input())

def NM():
	return map(int, input().split())

def L():
	return list(NM())
(n, m) = NM()
a = L()
mod = 10 ** 9 + 7

def comb(n, r):
	b = 1
	a = 1
	for i in range(r):
		b *= n - i
		a *= i + 1
		b %= mod
		a %= mod
	return b * pow(a, mod - 2, mod) % mod
print(comb(m + n, n + sum(a)))


(N, M) = map(int, input().split())
A = list(map(int, input().split()))
sa = sum(A)
MOD = 10 ** 9 + 7
if sa > M:
	print(0)
	return
if sa == M:
	print(1)
	return
x = 1 + sa + N
n = M - sa
bunsi = bunbo = 1
for i in range(max(x, n + 1), x + n):
	bunsi *= i
	bunsi %= MOD
for i in range(1, min(x, n + 1)):
	bunbo *= i
	bunbo %= MOD
ans = bunsi * pow(bunbo, MOD - 2, MOD)
ans %= MOD
print(ans)


def main():
	mod = 1000000007
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	s = sum(A)
	if s > m:
		return 0
	ans = 1
	inv = 1
	for i in range(s + n):
		ans *= m + n - i
		inv *= i + 1
		ans %= mod
		inv %= mod
	return ans * pow(inv, mod - 2, mod) % mod

def __starting_point():
	print(main())
__starting_point()


def solve(n, m, aaa):
	s = sum(aaa)
	if s > m:
		return 0
	ms = m - s
	MOD = 10 ** 9 + 7
	f = 1
	for i in range(2, n + s + 1):
		f = f * i % MOD
	ans = pow(f, MOD - 2, MOD)
	for x in range(m + n, ms, -1):
		ans = ans * x % MOD
	return ans
(n, m) = list(map(int, input().split()))
aaa = list(map(int, input().split()))
print(solve(n, m, aaa))


def ncr_mod(n, r, mod):
	(a, b) = (1, 1)
	for i in range(r):
		a *= n - i
		a %= mod
		b *= i + 1
		b %= mod
	return a * pow(b, mod - 2, mod) % mod
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = ncr_mod(m + n, sum(a) + n, mod)
print(ans)


(N, M) = list(map(int, input().split()))
A = [int(i) for i in input().split()]
sumA = sum(A)
mod = 10 ** 9 + 7

def inv(x):
	return pow(x, mod - 2, mod)
ans = 1
F = 1
for i in range(N + sumA):
	ans *= N + M - i
	ans %= mod
	F *= i + 1
	F %= mod
ans *= inv(F)
ans %= mod
print(ans)


mod = 10 ** 9 + 7

def comb(n, m):
	ans = 1
	(a, b) = (1, 1)
	for i in range(1, m + 1):
		a = a * (n - i + 1) % mod
		b = b * i % mod
		ans %= mod
	return a * pow(b, mod - 2, mod) % mod
(N, M) = map(int, input().split())
S = sum(map(int, input().split()))
print(comb(M + N, S + N))


(N, M) = map(int, input().split())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
S = sum(A)

def cmb(a, b, mod):
	if a < b:
		return 0
	b = min(b, a - b)
	num = 1
	for i in range(b):
		num = num * (a - i) % mod
	den = 1
	for i in range(1, b + 1):
		den = den * i % mod
	return num * pow(den, mod - 2, mod) % mod
print(cmb(M + N, S + N, mod))


(n, m) = map(int, input().split())
(*a,) = map(int, input().split())
mod = 10 ** 9 + 7
(l, r) = (1, 1)
for i in range(n + sum(a)):
	(l, r) = (l * (n + m - i) % mod, r * (i + 1) % mod)
print(l * pow(r, mod - 2, mod) % mod)


import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter
import sys
readline = sys.stdin.readline
INF = 1 << 60

def read_int():
	return int(readline())

def read_int_n():
	return list(map(int, readline().split()))

def read_float():
	return float(readline())

def read_float_n():
	return list(map(float, readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def ep(*args):
	print(*args, file=sys.stderr)

def epp(o):
	import pprint
	pprint.pprint(o, stream=sys.stderr)

def gen_2d_array(n, m, fill=0):
	if callable(fill):
		return [[fill()] * m for _ in range(n)]
	else:
		return [[fill] * m for _ in range(n)]

def gen_3d_array(n, m, k, fill=0):
	if callable(fill):
		return [[[fill()] * k for _ in range(m)] for _ in range(n)]
	else:
		return [[[fill] * k for _ in range(m)] for _ in range(n)]

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.perf_counter()
		ret = f(*args, **kwargs)
		e = time.perf_counter()
		ep(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(N, M, A):
	mod = 10 ** 9 + 7
	S = sum(A)
	a = 1
	b = 1
	for i in range(1, N + S + 1):
		a *= i
		a %= mod
		b *= M + N - i + 1
		b %= mod
	return b * pow(a, mod - 2, mod) % mod

def main():
	(N, M) = read_int_n()
	A = read_int_n()
	print(slv(N, M, A))

def __starting_point():
	main()
__starting_point()


import sys

def read_str():
	return sys.stdin.readline().strip()

def read_int():
	return int(sys.stdin.readline().strip())

def read_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def read_str_split():
	return list(sys.stdin.readline().strip())

def read_int_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def nCr(n, r, MOD):
	(a, b) = (1, 1)
	for i in range(r):
		a = a * (n - i) % MOD
		b = b * (i + 1) % MOD
	return a * pow(b, MOD - 2, MOD) % MOD

def Main():
	(N, M) = read_ints()
	A = read_int_list()
	print(nCr(N + M, N + sum(A), 10 ** 9 + 7))

def __starting_point():
	Main()
__starting_point()


(N, M) = map(int, input().split())
A = list(map(int, input().split()))
a = sum(A)
base = 10 ** 9 + 7

def fact(x):
	r = 1
	for i in range(1, x + 1):
		r *= i
		r %= base
	return r
ans = 1
for i in range(a + N):
	ans *= M + N - i
	ans %= base
ans *= pow(fact(a + N), base - 2, base)
ans %= base
print(ans)


def comb(n, m):
	p = 10 ** 9 + 7
	inv = [0] * (m + 1)
	finv = [0] * (m + 1)
	inv[1] = 1
	finv[0] = 1
	finv[1] = 1
	for i in range(2, m + 1):
		inv[i] = -(p // i) * inv[p % i] % p
		finv[i] = finv[i - 1] * inv[i] % p
	if m > n:
		return 0
	elif n < 0 or m < 0:
		return 0
	else:
		ans = 1
		for i in range(n, n - m, -1):
			ans = ans * i % p
		return ans * finv[m] % p
(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
s = sum(a)
print(comb(m + n, s + n))


import sys
(N, M) = list(map(int, input().split()))
A = list(map(int, input().split()))
P = int(1000000000.0 + 7)
sumA = sum(A)

def comb(n, r):
	if n < r or r < 0:
		return 0
	nume = 1
	deno = 1
	for i in range(1, r + 1):
		nume = nume * (n - i + 1) % P
		deno = deno * i % P
	deno_inv = pow(deno, P - 2, P)
	return nume * deno_inv % P
print(comb(M + N, N + sumA))