#P9159. 「GLR-R4」大暑
「GLR-R4」大暑
Background
“Sometimes sparse stars fall on the painted eaves, a few fireflies drifting.”
At the National Music Festival, by the time Tianyi and her group arrived, Fucheng was already overflowing with a carnival-like atmosphere. Some nervous young people gathered here, however, seemed a bit out of place.
“Anyway, this must be the terminal station, right?”
The rehearsal ended once again with the sound of strings. Then it began again, and ended again.
“A Ling, let’s go out for a walk.”
Great Heat “Painting every gaze with a patch of blue, melting away the bitterness.”
Problem Description
“A Ling, look at this painting on the brochure. It’s so strange.”
In the brochure, the production process of the huge artwork that “combines art and technology” is as follows:
First, the staff draw point-lattice diagrams of size . Any two diagrams are far away from each other, and in the subsequent process they are independent of each other. For the -th diagram, let the bottom-left corner be at . The set of points in the lattice is , where and .
Next, let the set contain all permutations of order of . For the -th diagram, the staff use the -th smallest permutation in lexicographic order, , to match and connect and : for a point , draw a line segment connecting it to the point .
Finally comes the exciting coloring step. For each in the -th diagram, starting from , follow the line segment drawn in the previous step, travel along any segments or polylines, reach any point in , and color this segment or polyline with the -th color. In addition, to avoid different colors mixing together, it is required that, among all diagrams, the total length of segments that have been colored by more than one color is .
The coloring of the painting shown to Tianyi and her group is clearly very careless, so Tianyi wants to know how many coloring schemes are possible. Define two coloring schemes to be different if and only if there exists an index and some point such that, after both schemes are completed, in the -th diagram the sets of colors that have colored point are different.
You only need to tell Tianyi the result modulo . To simplify your computation, Tianyi carefully chose an interesting modulus.
(Please refer to Sample #1 explanation to confirm the statement.)
Input Format
Input one line with an integer , representing the parameter of the drawing process.
Output Format
Output one line with a non-negative integer, representing the number of coloring schemes modulo .
3
384
4
40344945
Hint
Sample #1 Explanation
After completing the first two steps, the full picture is as follows. form one point-lattice diagram. The relative positions of different diagrams are not important.

The following is one possible coloring scheme. Red, yellow, and blue correspond to the -th colors respectively.

Sample #2 Explanation
The true value of the answer is .
Constraints
For of the data, .
For different subtasks, the constraints are as follows:
| Subtask ID | Subtask Score | |
|---|---|---|
Translated by ChatGPT 5