Multinomial Coefficients

One of the first formulas we were taught in high school mathematics is (a + b)2 = a2 + 2ab + b2. Later on, we learned that this is a special case of the expansion (a + b)n, in which the coefficient of akbn−k is the number of combinations of n things taken k at a time. We never learned (at least I never did ...) what happens if instead of a binomial a+b we have a multinomial a+b+c+...+x. Your task is to write a program that, given a multinomial m = a1 +a2 +...+ak , k ≥ 1, computes the coefficient of a given term in the expansion of mn, n ≥ 1. The given term is specified by a sequence of k integer numbers z1, z2, . . . , zk, representing the powers of a1, a2, . . . , ak in the expansion. Note that z1+z2+...+zk =n. Forexample,thecoefficientofab2cin(a+b+c)4 is12. Input The input file contains several test cases, each of them with three lines. The first line contains a number representing the value of n. The second line contains a number representing the value of k. The third line contains k numbers, representing the values of z1, z2, . . . , zk. All test cases are such that k ≤ 100 and the computed coefficient is less than 231. Output For each test case, write to the output one line. This line contains one integer number representing the value of the coefficient of the term az1 · az2 · ...·azk in the expansion of (a1 +a2 +...+ak)n. k Sample Input 4 3 121 7 4 2302 Sample Output 12 210 12