시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB1000.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$.

예제 입력 1

3 3
2 2 3
2 3 3

예제 출력 1

89

예제 입력 2

1 1
1
2

예제 출력 2

0

예제 입력 3

5 5
2 2 3 3 3
2 2 2 3 3

예제 출력 3

49049891

예제 입력 4

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

예제 출력 4

808346164

예제 입력 5

2 3
2 3
3 1 5

예제 출력 5

0