Under construction

Still being built. Things may change

Power

Interview

Time limit1sMemory limit1024 MB

Summary
For each column j, raise the first-row value a_j to the power j+1, add all these diagonal powers, and print the sum modulo m.
Level

Easy3 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

The table has n+1n + 1 rows and nn columns. The first row holds positive integers. Each of the next nn rows holds the powers of the numbers in the first row, in order: the second power, the third power, and so on.

In the table below, n=4n = 4. The rows hold the powers of 3, 5, 2, and 1 up to the fifth power.

3521
92541
2712581
81625161
2433125321

Write a program power that adds the numbers on the diagonal (the bold cells) and prints the sum modulo mm. For the example with m=3m = 3, the sum is 9 + 125 + 16 + 1 = 151. The remainder of 151 divided by 3 is 1, so the answer is 1.

Input

The first line contains the positive integers nn and mm. The second line contains the nn numbers of the first row, separated by spaces.

Output

Print the sum of the diagonal numbers modulo mm as a single integer.

Constraints

n≤1000000n \le 1000000, m≤10000000m \le 10000000. The numbers in the first row are positive integers less than 100000.

Examples1

  1. Example 1

    Input
    4 3
    3 5 2 1
    
    Expected output
    1