Double Derangement
시간 제한1초메모리 제한1024 MB
모든 i에서 c[i]가 a[i]와 b[i] 모두와 다른 순열 c의 개수를 센다. N은 최대 16이다.
문제
You are given two permutations and , each of length containing every integer in the range . Your task is to construct a new permutation of length that contains every integer in the range , such that for every index (-indexed), the following condition is satisfied:
\[c_i \neq a_i \quad \text{and} \quad c_i \neq b_i.\]
In other words, for no index can be equal to or .
Given the permutations and , determine how many such permutations exist.
입력
The first line of input contains a single integer , denoting the number of test cases.
For each test case, the input is as follows:
- The first line of each test case contains a single integer, , denoting the length of the permutations. ()
- The next line contains space-separated integers, denoting the permutation . Here, the -th integer denotes . ( )
- The next line contains space-separated integers, denoting the permutation . Here, the -th integer denotes . ( )
Sum of over all cases .
출력
Output how many such permutations described in the problem exist.
힌트
You may have to use a type larger than a -bit integer to prevent overflow in this problem.