#P10004. Permutation Ascents and Inverse Permutations

    ID: 11985 Type: Default 1000ms 256MiB

Permutation Ascents and Inverse Permutations

Permutation Ascents and Inverse Permutations

Given a positive integer \(n\), for each pair \((x,y)\) with \(0 \le x,y < n\), count the number of permutations \(p\) of \(\{1,2,\dots,n\}\) satisfying the following conditions:

\[ \sum_{i=1}^{n-1} [p_i < p_{i+1}] = x, \quad \sum_{i=1}^{n-1} [p^{-1}_i < p^{-1}_{i+1}] = y, \] where \(p^{-1}\) denotes the inverse permutation of \(p\) (that is, \(p^{-1}_{p_i}=i\)). The answer should be output modulo the given prime number \(MOD\).

inputFormat

The input consists of two integers: \(n\) and \(MOD\). Here, \(n\) represents the number of elements in the permutation, and \(MOD\) is a prime number used for modulo operations.

outputFormat

Output an \(n \times n\) matrix. The element in the \(x\)-th row and \(y\)-th column (0-indexed) is the number of permutations \(p\) satisfying the conditions with \(\sum[p_i < p_{i+1}] = x\) and \(\sum[p^{-1}_i < p^{-1}_{i+1}] = y\), taken modulo \(MOD\). Print each row on a new line with values separated by a single space.

sample

1 1000000007
1