supersuma

Time limit: 0.05s Memory limit: 256MB Input: Output:

We are given an array AA of length NN. The green operation applied to AA consists of two steps:

  • We create an array BB, which is at first empty. We consider all subsets of AA, including the empty subset, we compute the sum of the values there and then we add these sums in BB.
  • AA becomes BB and BB is once again empty.

Task

You must print the sum modulo MM of the values from AA after applying the green operation KK times.

Input data

The input will contain on the first line NN, KK and MM. The next line will contain the values from array AA.

Output data

The first line will contain a single number, the required sum.

Constraints and clarifications

  • 1N501 \leq N \leq 50
  • 1K1091 \leq K \leq 10^9
  • 1M109+71 \leq M \leq 10^9 + 7
  • 0AiM0 \leq A_i \leq M
  • MM is odd.
# Score Constraints
1 20 M=109+7M = 10^9 + 7, K=1K = 1
2 10 M=109+7M = 10^9 + 7, K=2K = 2
3 10 K=2K = 2
4 20 M500M \leq 500, K5104K \leq 5 \cdot 10^4
5 20 M109+7M \leq 10^9 + 7, K5104K \leq 5 \cdot 10^4
6 20 No additional constraints

Example 1

stdin

3 1 9999
1 2 3

stdout

24

Explanation

In the first example, array AA after the green operation is 0 1 2 3 3 4 5 60 \ 1 \ 2 \ 3 \ 3 \ 4 \ 5 \ 6.

Example 2

stdin

3 4 29
0 23 0

stdout

26

Example 3

stdin

4 50000 49999
2 0 2 3

stdout

43310

Log in or sign up to be able to send submissions!