Buggy python submission (verdict: Time Limit Exceeded):
# http://drken1215.hatenablog.com/entry/2020/01/12/011700

def main():
    from functools import lru_cache

    MOD = 10 ** 9 + 7

    N, K = map(int, input().split())
    *a, = map(int, input().split())

    # -+-+-+-prepare combination-+-+-+-
    # -+-+-+-START-+-+-+-
    fact = [-1] * (N + 1)
    fact[0] = 1
    fact[1] = 1
    for x in range(2, N + 1):
        fact[x] = x * fact[x - 1] % MOD

    invs = [1] * (N + 1)
    invs[N] = pow(fact[N], MOD - 2, MOD)
    for x in range(N - 1, 0, -1):
        invs[x] = invs[x + 1] * (x + 1) % MOD

    @lru_cache(maxsize=None)
    def cmb(n, r):
        if n - r < r: return cmb(n, n - r)
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        return fact[n] * invs[r] * invs[n - r] % MOD

    # -+-+-+-END-+-+-+-

    dp = [[0] * (N + 1) for _ in range(K + 1)]
    dp[0][0] = 1

    for i, ai in enumerate(a):
        for counted in range(N + 1):
            for to_count in range(min(N - counted, ai) + 1):
                dp[i + 1][counted + to_count] = (
                                                        dp[i + 1][counted + to_count]
                                                        + dp[i][counted]
                                                        * cmb(N - counted, to_count)
                                                        * cmb(N - to_count, ai - to_count)
                                                ) % MOD

    print(dp[K][N])


if __name__ == '__main__':
    main()


Fixed submission:
# http://drken1215.hatenablog.com/entry/2020/01/12/011700

def main():
    MOD = 10 ** 9 + 7

    N, K = map(int, input().split())
    *a, = map(int, input().split())

    # -+-+-+-prepare combination-+-+-+-
    # -+-+-+-START-+-+-+-
    fact = [0] * (N + 1)
    fact[0] = 1
    fact[1] = 1
    for x in range(2, N + 1):
        fact[x] = x * fact[x - 1] % MOD

    invs = [1] * (N + 1)
    invs[N] = pow(fact[N], MOD - 2, MOD)
    for x in range(N - 1, 0, -1):
        invs[x] = invs[x + 1] * (x + 1) % MOD

    def cmb(n, r):
        if n - r < r: return cmb(n, n - r)
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        return (((fact[n] * invs[r]) % MOD) * invs[n - r]) % MOD

    # -+-+-+-END-+-+-+-

    dp = [0] * (N + 1)
    dp[0] = 1

    for i, ai in enumerate(a):
        ndp = [0] * (N + 1)
        for counted in range(N + 1):
            for to_count in range(min(N - counted, ai) + 1):
                ndp[counted + to_count] = (
                                                  ndp[counted + to_count]
                                                  + dp[counted]
                                                  * cmb(N - counted, to_count)
                                                  * cmb(N - to_count, ai - to_count)
                                          ) % MOD
        dp = ndp

    print(dp[N])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# http://drken1215.hatenablog.com/entry/2020/01/12/011700

def combination_builder(max_value, mod):
    fact = [-1] * (max_value + 1)
    fact[0] = 1
    fact[1] = 1
    for x in range(2, max_value + 1):
        fact[x] = x * fact[x - 1] % mod

    invs = [1] * (max_value + 1)
    invs[max_value] = pow(fact[max_value], mod - 2, mod)
    for x in range(max_value - 1, 0, -1):
        invs[x] = invs[x + 1] * (x + 1) % mod

    def _combination(n, r):
        """combination(max_value, all)"""
        nonlocal fact, invs, mod

        if n - r < r: return _combination(n, n - r)
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        return fact[n] * invs[r] * invs[n - r] % mod

    return _combination


def main():
    MOD = 10 ** 9 + 7

    n, k = map(int, input().split())
    *a, = map(int, input().split())

    cmb = combination_builder(max_value=n, mod=MOD)

    dp = [[0] * (n + 1) for _ in range(k + 1)]
    dp[0][0] = 1

    for i, ai in enumerate(a):
        for counted in range(n + 1):
            for to_count in range(ai + 1):
                if counted + to_count > n:
                    break
                dp[i + 1][counted + to_count] = (
                                                        dp[i + 1][counted + to_count]
                                                        + dp[i][counted]
                                                        * cmb(n - counted, to_count)
                                                        * cmb(n - to_count, ai - to_count)
                                                ) % MOD

    print(dp[k][n])


if __name__ == '__main__':
    main()


Fixed submission:
# http://drken1215.hatenablog.com/entry/2020/01/12/011700

def main():
    MOD = 10 ** 9 + 7

    N, K = map(int, input().split())
    *a, = map(int, input().split())

    # -+-+-+-prepare combination-+-+-+-
    # -+-+-+-START-+-+-+-
    fact = [0] * (N + 1)
    fact[0] = 1
    fact[1] = 1
    for x in range(2, N + 1):
        fact[x] = x * fact[x - 1] % MOD

    invs = [1] * (N + 1)
    invs[N] = pow(fact[N], MOD - 2, MOD)
    for x in range(N - 1, 0, -1):
        invs[x] = invs[x + 1] * (x + 1) % MOD

    def cmb(n, r):
        if n - r < r: return cmb(n, n - r)
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        return (((fact[n] * invs[r]) % MOD) * invs[n - r]) % MOD

    # -+-+-+-END-+-+-+-

    dp = [0] * (N + 1)
    dp[0] = 1

    for i, ai in enumerate(a):
        ndp = [0] * (N + 1)
        for counted in range(N + 1):
            for to_count in range(min(N - counted, ai) + 1):
                ndp[counted + to_count] = (
                                                  ndp[counted + to_count]
                                                  + dp[counted]
                                                  * cmb(N - counted, to_count)
                                                  * cmb(N - to_count, ai - to_count)
                                          ) % MOD
        dp = ndp

    print(dp[N])


if __name__ == '__main__':
    main()