409112: GYM103439 D LIS Counting

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. LIS Countingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given integers $$$N, M$$$ with and a prime modulo $$$P$$$.

Consider all permutations of length $$$N \cdot M$$$ such that the length of their longest increasing subsequence equals $$$N$$$ and the length of their longest decreasing subsequence equals $$$M$$$.

Define $$$f(pos, val)$$$ for each $$$1 \le pos, val \le N \cdot M$$$ as the number of such permutations in which the $$$pos$$$-th element of the permutation equals to $$$val$$$.

Find $$$f(pos, val)$$$ for all $$$1 \le pos, val \le NM$$$, modulo $$$P$$$.

Input

The only line of input contains three integers $$$N$$$ $$$M$$$ $$$P$$$ ($$$1 \le N \cdot M \le 100$$$, $$$10^8 \le P \le 10^9$$$, $$$P$$$ is prime).

Output

Print a table of size $$$NM \times NM$$$, the $$$val$$$-th value in $$$pos$$$-th line should be equal to $$$f(pos, val) \bmod P$$$.

ExamplesInput
3 2 998244353
Output
0 10 10 5 0 0 
10 0 0 6 9 0 
10 0 0 4 6 5 
5 6 4 0 0 10 
0 9 6 0 0 10 
0 0 5 10 10 0 
Input
1 7 100000007
Output
0 0 0 0 0 0 1 
0 0 0 0 0 1 0 
0 0 0 0 1 0 0 
0 0 0 1 0 0 0 
0 0 1 0 0 0 0 
0 1 0 0 0 0 0 
1 0 0 0 0 0 0 

加入题单

上一题 下一题 算法标签: