Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of color *i* + 1 for all *i* from 1 to *k* - 1. Now he wonders how many different ways this can happen.
The first line of input will have one integer *k* (1 ≤ *k* ≤ 1000) the number of colors.

Then, *k* lines will follow. The *i*-th line will contain *c*<sub class="lower-index">*i*</sub>, the number of balls of the *i*-th color (1 ≤ *c*<sub class="lower-index">*i*</sub> ≤ 1000).

The total number of balls doesn't exceed 1000.
#!/usr/bin/env python
# 554C_colored.py - Codeforces.com 554C Colored quiz
#
# Copyright (C) 2015 Sergey
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Input

The first line of input will have one integer k (1<=k<=1000) the number
of colors.

Then, k lines will follow. The i-th line will contain ci, the number of
balls of the i-th color (1<=ci<=1000).

The total number of balls doesn't exceed 1000.
Output

A single integer, the number of ways that Kyoya can draw the balls from
the bag as described in the statement, modulo 1_000_000_007.

"""

# Standard libraries
import unittest
import sys
import re

# Additional libraries


###############################################################################
# Colored Class
###############################################################################


class Colored:
    """ Colored representation """

    MOD = 1000000007

    def __init__(self, args):
        """ Default constructor """

        self.list = args

    def factm(self, n):
        result = 1
        for i in range(n):
            result *= i + 1
            result %= self.MOD
        return result

    def binom(self, n, k):
        return self.factm(n) // (self.factm(n - k) * self.factm(k))

    def f(self, i):
        if i == 0:
            return 1
        bin = self.binom(sum(self.list[:i+1]) - 1, self.list[i] - 1)
        return bin * self.f(i - 1)

    def calculate(self):
        """ Main calcualtion function of the class """
        result = self.f(len(self.list) - 1)

        return str(result)


###############################################################################
# Executable code
###############################################################################


def get_inputs(test_inputs=None):

    it = iter(test_inputs.split("\n")) if test_inputs else None

    def uinput():
        """ Unit-testable input function wrapper """
        if it:
            return next(it)
        else:
            return input()

    # Getting string inputs
    num = int(uinput())
    nums = [int(uinput()) for i in range(num)]

    # Decoding inputs
    inputs = nums

    return inputs


def calculate(test_inputs=None):
    """ Base class calculate method wrapper """
    return Colored(get_inputs(test_inputs)).calculate()


###############################################################################
# Unit Tests
###############################################################################


class unitTests(unittest.TestCase):

    def test_sample_tests(self):
        """ Quiz sample tests. Add \n to separate lines """
        self.assertEqual(calculate("3\n2\n2\n1"), "3")
        self.assertEqual(calculate("4\n1\n2\n3\n4"), "1680")

    def test_get_inputs(self):
        """ Input string decoding testing """
        self.assertEqual(get_inputs("2\n1\n3"), [1, 3])

    def test_Colored_class__basic_functions(self):
        """ Colored class basic functions testing """

        # Constructor test
        d = Colored([2, 1])
        self.assertEqual(d.list, [2, 1])

        # Factorial using modulo
        self.assertEqual(d.factm(4), 24)

        # Binominal
        self.assertEqual(d.binom(2, 1), 2)

        # Dynamic programming function, solution for i colors
        self.assertEqual(d.f(0), 1)
        self.assertEqual(d.f(1), 1)


if __name__ == "__main__":
    if sys.argv[-1] == "-ut":
        unittest.main(argv=[" "])

    # Print the result string
    print(calculate())
