Lost Table
시간 제한2초메모리 제한2048 MB
주어진 각 행의 최댓값과 각 열의 최댓값을 만족하는 n×m 양의 정수 표의 개수를 10^9+7로 나눈 나머지를 구하고, 불가능하면 0을 출력한다.
문제
Er-Tostik had a table of size 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 . Help Er-Tostik to get his table back.
입력
The first line of input contains two integers and (): the dimensions of the table.
The second line contains integers (): the maximum values in each row.
The third line contains integers (): 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 .
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 .