#P17284. 「IXOI R2」想不出来
「IXOI R2」想不出来
Background
As you can see, the problem setter cannot think of a problem name again.

[Big Head].jpg
Problem Description
Given a sequence of length .
You have a sequence of length , initially .
Define one operation as: choose , and move the numbers at positions and in the sequence to position .
Formally, each operation can be seen as setting:
- ;
- ;
- .
In particular, if position or does not exist, then no operation is performed at position or .
We call a sequence stupid if and only if it can be generated from the initial sequence by performing the operation any number of times.
We call two sequences essentially different if and only if .
Define the weight of a sequence as:
Now, compute the sum of weights of all essentially different stupid sequences , and output the result modulo .
Here, it is considered that .
Input Format
The input has two lines. The first line contains an integer . The second line contains an array of length .
Output Format
Output one integer, representing the sum of weights of all essentially different stupid sequences , modulo .
6
2 3 1 5 6 6
648718
5
17 43 2 6 7
207004448
Hint
This problem uses bundled testdata.
| Subtask | Special Property | Score | |
|---|---|---|---|
| None | |||
| None |
For all data, it is guaranteed that:
It is guaranteed that .
Translated by ChatGPT 5