AT_abc214_g [ABC214G] Three Permutations
Description
[problemUrl]: https://atcoder.jp/contests/abc214/tasks/abc214_g
$ (1,\ \dots,\ N) $ の順列 $ p\ =\ (p_1,\ \dots,\ p_N),\ q\ =\ (q_1,\ \dots,\ q_N) $ が与えられます。
$ (1,\ \dots,\ N) $ の順列 $ r\ =\ (r_1,\ \dots,\ r_N) $ であって、全ての $ i\ \,\ (1\ \leq\ i\ \leq\ N) $ に対し $ r_i\ \neq\ p_i $ かつ $ r_i\ \neq\ q_i $ となるようなものの総数を $ (10^9\ +\ 7) $ で割った余りを求めてください。
Input Format
N/A
Output Format
N/A
Explanation/Hint
### 制約
- $ 1\ \leq\ N\ \leq\ 3000 $
- $ 1\ \leq\ p_i,\ q_i\ \leq\ N $
- $ p_i\ \neq\ p_j\ \,\ (i\ \neq\ j) $
- $ q_i\ \neq\ q_j\ \,\ (i\ \neq\ j) $
- 入力は全て整数である。
### Sample Explanation 1
$ (3,\ 4,\ 1,\ 2),\ (3,\ 4,\ 2,\ 1),\ (4,\ 3,\ 1,\ 2),\ (4,\ 3,\ 2,\ 1) $ の $ 4 $ つが条件を満たします。
### Sample Explanation 2
答えが $ 0 $ になることもあります。
### Sample Explanation 3
$ (10^9\ +\ 7) $ で割った余りを出力することに注意してください。