Product Sum Queries
Time limit2sMemory limit512 MB
For each query K, sum the products of all K-element subsets of A, counting positions separately, modulo 100003.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
You are given a sequence of numbers. Write a program that answers queries about it.
Each query is a single integer . Consider every way of choosing elements of , take the product of the chosen numbers for each way, add all of those products, and print the sum modulo .
Choices are distinguished by position. Elements with equal values at different positions give different choices, so the number of ways is always the binomial coefficient .
Input
The first line contains ().
The second line contains the elements (), separated by spaces.
The third line contains the number of queries ().
Each of the next lines contains one ().
Output
Print the answer to each query on its own line, in the order the queries are given.
Hint
For and the choices are , , . The products are , , and the sum is .
For and there are still three choices, because the two s sit at different positions. The products are , , and the sum is .