A product is a multiset of n ingredients chosen from m qualities; find the sum of the products of qualities over all such multisets, mod 1e9+7.
Medium7CombinatoricsMathDynamic programmingNo attempts yetTime limit1sMemory limit128 MBcubelover combines ingredients in this order.
A product made in this cauldron is decided without regard to the order the ingredients went in. If the ingredients differ, the product always differs too. The quality of a product equals the product of the qualities of all the ingredients that went in.
For example, suppose you use a lizard tail of quality 2 and a fairy wing of quality 3. If adding the lizard tail, the fairy wing, and the lizard tail in that order yields apple juice, the quality of that apple juice is 2×3×2=12. The order has no effect on the product, so adding the fairy wing, the lizard tail, and the lizard tail yields the same apple juice.
Today cubelover combines n ingredients. The warehouse holds m kinds of ingredients whose qualities are a1,a2,…,am, all different, and he may add the same kind any number of times. Two products are the same exactly when they use the same count of every kind. There are so many products that cubelover could not count them himself. Find the sum of the qualities of every product he can make.
The first line has two integers n and m separated by a space. (1≤n≤109, 1≤m≤103)
The second line has a1,a2,…,am separated by spaces. (1≤ai≤109, all ai are different)
Print on the first line the sum of the qualities of every product he can make, modulo 1000000007.