P16449 [XJTUPC 2026] Strange Merchant: One Carat Seven-Fresh Fish Balls

Description

Once upon a time, there were two good friends named Xiao Yi and Xiao Huan. They were both famous sorting masters! For a permutation $p_1, p_2,\cdots, p_n$ of length $n$, Xiao Yi can, in one operation, choose an interval and cyclically shift it to the right by one position, while Xiao Huan can, in one operation, swap the positions of two different elements. Here, a permutation $p_1, p_2,\cdots, p_n$ means a sequence satisfying $\{p_1, p_2,\cdots, p_n\}=\{1,2,\cdots,n\}$. Formally, - One operation of Xiao Yi: choose an interval $[l,r]$ ($1\le l\le r\le n$). If the elements in this interval are $p_l,p_{l+1},p_{l+2},\dots,p_r$, then after the operation they become $p_r,p_l,p_{l+1},p_{l+2}\dots,p_{r-1}$. - One operation of Xiao Huan: choose two different positions $i,j$ ($1\le i

Input Format

The input contains one line with two integers $n$ and $mod$ ($1\le n\le 150$, $2\le mod \le 10^9+7$), separated by a single space.

Output Format

Output $n$ lines, each containing $n$ integers separated by a single space. The $j$-th integer in the $i$-th line represents $P_{i-1,j-1} \bmod mod$.

Explanation/Hint

Translated by ChatGPT 5