#C4502. Product Excluding Current

    ID: 48048 Type: Default 1000ms 256MiB

Product Excluding Current

Product Excluding Current

You are given an array of integers and a list of query indices. For each query, you need to compute the product of all elements in the array except the element at the queried index, modulo \(10^9+7\). Since the product can be very large, you must output the result modulo \(10^9+7\). Note that if the array contains zeros, the calculations must account for them properly. In the special case when the array consists of a single element, the answer is defined to be 1.

inputFormat

The input is given via standard input (stdin).

The first line contains two space-separated integers (N) and (Q), where (N) is the number of elements in the array and (Q) is the number of queries.

The second line contains (N) space-separated integers representing the array.

The third line contains (Q) space-separated integers representing the query indices (0-indexed).

outputFormat

For each query, output the product of all array elements except the one at the queried index, modulo (10^9+7). The answers for all queries should be output on one line, separated by a single space, via standard output (stdout).## sample

6 3
1 2 3 4 5 6
0 1 5
720 360 120