Given integers , , and a sequence .
There is a stack, initially empty. Perform the following insertion operation times:
Find the expected number of elements in the stack after insertions, modulo .
In other words, the expected value can be written as (). You need to find the unique integer such that .
The first line of input contains two integers and . The second line contains integers, namely .
The output should contain a single line with one integer: the expected value you computed.
3 2
1 2
961272342
3 3
1 2 1
779878403
6 10
3293122 304483210 0 920851348 548604332 397404204 78439209 998244352 439820043 291380245
168058624