| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 1 | 0 | 0 | 0.000% |
Er-Tostik had a table of size $n \times m$ with positive integers. Aldar-Kose decided to prank Er-Tostik and stole the table, but told Er-Tostik the maximum value in each row and column. Aldar-Kose will only return the table if Er-Tostik can tell how many different tables can have these maximum values. As their number can be very large, Aldar-Kose only asks to find this value modulo $10^9 + 7$. Help Er-Tostik to get his table back.
The first line of input contains two integers $n$ and $m$ ($1 \leq n, m \leq 2 \cdot 10^5$): the dimensions of the table.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$): the maximum values in each row.
The third line contains $m$ integers $b_1, b_2, \ldots, b_m$ ($1 \leq b_j \leq 10^9$): the maximum values in each column.
Output a line with a single integer: the number of different tables satisfying the conditions. Since the answer can be very large, output it modulo $10^9 + 7$.
Note that, as Aldar-Kose is mischievous, the input might not be consistent with any table at all. In such case, naturally, the correct answer is $0$.
3 3 2 2 3 2 3 3
89
1 1 1 2
0
5 5 2 2 3 3 3 2 2 2 3 3
49049891
12 13 2 2 2 3 3 4 4 4 4 5 5 5 2 3 3 3 3 4 5 5 5 5 5 5 5
808346164
2 3 2 3 3 1 5
0