D. Doping 2

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

GrandPaPà calls f(p)f(p) applied to a permutation p1,p2,,pnp_1,p_2,\ldots,p_n as the number of pairs (i,j)(i,j) such that i<ji<j and pi+1=pjp_i+1 = p_{j}. For example, f([1,2,3])=2f([1,2,3]) = 2, f([3,1,2])=1f([3,1,2]) = 1 and f([3,2,1])=0f([3,2,1]) = 0.

Given nn and a permutation pp of length nn, we define a permutation pp' of length nn to be kk-special if and only if:

  1. pp' is lexicographically smaller than pp, and
  2. f(p)=kf(p') = k.

Your task is to count for each 0kn10 \le k \le n - 1 the number of kk-special permutations modulo mm.

A permutation is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array) and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

A permutation aa of length nn is lexicographically smaller than a permutation bb of length nn if and only if the following holds: in the first position where aa and bb differ, the permutation aa has a smaller element than the corresponding element in bb.

Input

The first line contains two integers nn and mm (1n1001 \le n \le 100, 1m1091 \le m \le 10^9) — the length of the permutation and the required modulo.

The second line contains nn distinct integers p1,p2,,pnp_1, p_2, \ldots, p_n (1pin1 \le p_i \le n) — the permutation pp.

Output

Print nn integers, where the kk-th integer is the number of (k1)(k-1)-special permutations modulo mm.

Example 1

stdin

4 666012
1 3 4 2

stdout

0 0 2 1 

Note

The permutations that are lexicographically smaller than [1,3,4,2][1,3,4,2] are:

  • [1,2,3,4][1,2,3,4], f([1,2,3,4])=3f([1,2,3,4])=3;
  • [1,2,4,3][1,2,4,3], f([1,2,4,3])=2f([1,2,4,3])=2;
  • [1,3,2,4][1,3,2,4], f([1,3,2,4])=2f([1,3,2,4])=2.

Thus our answer is [0,0,2,1][0,0,2,1].

Example 2

stdin

10 60
10 9 8 7 6 5 4 3 2 1

stdout

0 53 20 32 14 14 32 20 53 1 

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