시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 1 | 1 | 1 | 100.000% |
Bobo has two permutations: $P = \{p_1, p_2, \ldots, p_n\}$ and $Q = \{q_1, q_2, q_3, q_4\}$. He would like to partition $P$ into four non-empty and contiguous parts in such a manner that:
Bobo wants to know the number of such partitions. As the number may be very large, you just need to print the answer modulo $(10^9 + 7)$.
The input contains zero or more test cases, and is terminated by end-of-file. For each test case:
The first line contains an integer $n$, the length of the first permutation $(4 \leq n \leq 10^6)$.
The second line contains $n$ integers $p_1, p_2, \dots, p_n$.
The third line contains four integers $q_1, q_2, q_3, q_4$.
It is guaranteed that the sum of all $n$ does not exceed $10^6$.
For each test case, output an integer denoting the answer.
10 2 1 4 3 10 9 8 7 5 6 2 4 1 3 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4
0 84