Gomory and Hu have started investing in cryptocurrencies. On their investment plan there are of the most popular cryptocurrencies known to them.
Every day, Gomory, being very passionate about investments, wants to invest GH in several cryptocurrencies. Since Hu is his much more careful and responsible friend, he allows Gomory to choose only a subset of these investments.
At the end of their investment plan, which lasts days, the two calculate their profit. Since they are very smart, they figured out how the cryptocurrency market works and how they can compute their profit. Thus, they realized that the final profit is the product of the GH units invested in each cryptocurrency.
Because they have such an exciting life, they will try all possible ways of investing, and at the very end they will count the money obtained from the entire process. The two ask for your help and ask you to compute how rich they will be.
Task
Formally, you are given and sequences of the form: , , , , , .
Starting from a zero array of length , for each , a subsequence of exact size is chosen from the array , and the elements at the positions in are incremented by in the array of length . After performing the operations, the product of the elements of the array is computed.
You are asked to output the sum of the products of the elements of the array modulo , over all possible ways of choosing the subsequences during the operations.
Input Data
On the first line, the numbers and are read, in this order, with the meaning from the statement.
On the next lines, the parameters for the days are given, in the following order: , , , , , .
Output Data
You must output a single number representing the sum of the products of the elements of the final array modulo , considering all possible ways of choosing the subsequences during the operations.
Constraints
| # | Points | Restrictions |
|---|---|---|
| 1 | 10 | , |
| 2 | 15 | |
| 3 | 30 | |
| 4 | 45 | No additional constraints |
Example
stdin
3 2
3 2 1 2 3
2 2 2 3
stdout
4
Explanation
In the given example, there are three possible final configurations:
- We choose on the first day , and on the second day . The final array will be , and the product of the elements is .
- We choose on the first day , and on the second day . The final array will be , and the product of the elements is .
- We choose on the first day , and on the second day . The final array will be , and the product of the elements is .
Thus, the answer is .