Alchemy
Time limit1sMemory limit128 MB
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.
- Level
Medium7 of 10
- Topics
- Combinatorics, Math, Dynamic programming
- Solved
- No attempts yet
Problem
cubelover combines ingredients in this order.
- Fill the cauldron with slime fluid and heat it over a fire.
- Add one ingredient, then stir slowly four times clockwise and twice counterclockwise.
- Offer a prayer facing east.
- Repeat steps 2 and 3 until every ingredient is in.
- Put out the fire and let the cauldron cool for 17 hours to finish the product.
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 and a fairy wing of quality . 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 . 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 ingredients. The warehouse holds kinds of ingredients whose qualities are , 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.
Input
The first line has two integers and separated by a space. (, )
The second line has separated by spaces. (, all are different)
Output
Print on the first line the sum of the qualities of every product he can make, modulo .