#abc214g. G - Three Permutations
G - Three Permutations
Score : points
问题描述
给定 的排列: 和 。
求满足以下条件的排列 的个数,对 取模:
对于所有 (),有 且 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Given are permutations of : and .
Find the number, modulo , of permutations of such that and for every .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4
1 2 3 4
2 1 4 3
Sample Output 1
4
There are four valid permutations: , , , and .
Sample Input 2
3
1 2 3
2 1 3
Sample Output 2
0
The answer may be .
Sample Input 3
20
2 3 15 19 10 7 5 6 14 13 20 4 18 9 17 8 12 11 16 1
8 12 4 13 19 3 10 16 11 9 1 2 17 6 5 18 7 14 20 15
Sample Output 3
803776944
Be sure to print the count modulo .
update @ 2024/3/10 09:32:07