#P9072. [CTS2023] 另一个欧拉数问题
[CTS2023] 另一个欧拉数问题
Background
You keep walking forward and meet an old man in a black robe. In front of the door there is a huge sand table, and the old man draws strange symbols on it with a branch in his hand.
The old man tells you that he has dreamed of one problem since he was young. Even now that he is old and frail, it seems he has only uncovered a small part of the answer.
“Maybe I should hand them over to you,” the old man says.
“Don’t worry too much. I don’t want to make it too hard for you. At least, I have already prepared the necessary tools for you.”
Problem Description
For a positive integer , consider the following sequence of length :
-
For each , the sequence contains exactly occurrences of .
-
For with , for any , we have .
We call a sequence that satisfies the above requirements an -order permutation.
Now you are given an -order permutation . You are also given and . Please compute how many -order permutations contain as a subsequence, and also satisfy:
- There are exactly indices such that .
You only need to output the result modulo .
Input Format
The first line contains four integers , , , .
The second line contains positive integers, which are guaranteed to form an -order permutation.
Output Format
Output one integer, the number of sequences that satisfy the requirements.
1 4 2 2
2 1
7
2 4 2 2
1 2 2 1
19
Hint
Constraints
Subtask 1 ( points): .
Subtask 2 ( points): , .
Subtask 3 ( points): .
Subtask 4 ( points): , .
Subtask 5 ( points): .
Subtask 6 ( points): no special restrictions.
For all testdata, it is guaranteed that , , , .
Hint
To make it easier for contestants to handle formal power series computations, we provide a template. You may refer to and use this template as needed, or choose not to use it.
Translated by ChatGPT 5