#P9418. [POI 2021/2022 R1] Impreza krasnali
[POI 2021/2022 R1] Impreza krasnali
Background
Translated from XXIX Olimpiada Informatyczna – Stage I Impreza krasnali.
Problem Description
There are people standing in a line in order. Each person holds a number, and these numbers form a permutation.
Each person will choose one of two options to report: the number held by the person on their left or the number held by the person on their right. Note that the first person and the -th person are not adjacent, so the first person always reports the second person’s number, and the -th person always reports the -th person’s number.
Now you are given the numbers reported by the people. Find how many different original permutations are possible.
Input Format
The first line contains a positive integer .
The second line contains integers, representing the number reported by each person.
Output Format
Output one integer: your answer modulo .
5
3 4 3 4 1
2
见附件
0
见附件
1
Hint
For all testdata, .
| Subtask ID | Additional Constraints | Points |
|---|---|---|
| 1 | 12 | |
| 2 | 30 | |
| 3 | ||
| 4 | 28 |
Translated by ChatGPT 5