Lost Table

시간 제한2초메모리 제한2048 MB

문제

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$.