#P8561. 送别(Farewell)
送别(Farewell)
Background
It is time to say goodbye again... The time we spent together was short. I wonder if it brought you a good experience.
I held this contest because I wanted to leave myself some precious memories. Although my own skill is not high, it still means a lot to me.
After a long time of preparation, since this is a farewell, it should have been more grand—yet I do not have that ability. Otherwise, I would not have been able to make only a problem of this level as the finale.
Since so, do not let this parting become a forever goodbye... I will do my best, for our next meeting. This is my selfish request, but please wait for me to come back.
My poor words cannot express the feelings in my heart. Then let us just do this—quietly enjoy this time before we part.
Problem Description
Rin arrived at a wonderful planet called Gnilrits, where a wonderful kind of Gnilrits people lives.
In this species, except for individuals who have infinite lifespan but cannot reproduce, let the total number of other people in year be . She learned that they follow the rule , where and .
In year , if , then the following events will happen in order on the planet:
-
All people are assigned into identical houses, with no empty house (each person is distinct).
-
From each house, build one directed road to another house (possibly itself). Also, for every house, there must be a road pointing to it. In the end, there will be directed cycles, including self-loops.
Note that after step 1, since different people live in the houses, the houses become different from each other.
Rin thought of a question: let the total number of ways to assign houses and build roads in year be (if then ). What is the sum of all for ?
While thinking about this, she suddenly woke up—it turned out it was only a dream. She wanted to share what she saw in the dream with Mio, but then she remembered that Mio, who used to be by her side, has now left.
There is no way, but Rin still wants to know the answer. Please help compute it. The result may be very large; you only need to output it modulo .
Input Format
The first line contains three positive integers .
Output Format
Output one integer on one line, representing the answer.
4 2 2
765
233 2 99
161697303
7 4 5
322237710
10 3 17
146281933
1919810 114514 2333
426283611
Hint
[Sample 1 Explanation]
When , .
For , . First, assign distinct people into identical houses, which has ways. Then connect the now-distinct houses with directed roads to form cycle, which has only ways, so .
(For a more detailed explanation, see here.)
For , . Assign people into houses, which has ways. Building roads among the houses to form cycles has ways, so the total number of ways is .
Therefore the answer is .
[Constraints]
This problem uses bundled testdata.
Subtask 1 (7 pts): ,.
Subtask 2 (11 pts): .
Subtask 3 (13 pts): .
Subtask 4 (19 pts): ,.
Subtask 5 (23 pts): ,.
Subtask 6 (27 pts): no special constraints.
For of the data, , , .
[Hint]
This problem is not hard, but it may require some constant-factor optimizations.
Translated by ChatGPT 5