아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Filling the Grid

시간 제한1초메모리 제한1024 MB

요약
각 행과 열이 처음부터 몇 칸까지 채워지는지 주어질 때, 이를 만족하는 격자의 수를 10^9+7로 나눈 나머지로 구한다.
난이도

보통10점 중 5점

유형
구현, 조합론, 수학
정답자
아직 제출이 없습니다

문제

Suppose there is a h×wh \times w grid consisting of empty or full cells. Let's make some definitions:

  • r_ir\_{i} is the number of consecutive full cells connected to the left side in the ii-th row (1≤i≤h1 \le i \le h). In particular, r_i=0r\_i=0 if the leftmost cell of the ii-th row is empty.
  • c_jc\_{j} is the number of consecutive full cells connected to the top end in the jj-th column (1≤j≤w1 \le j \le w). In particular, c_j=0c\_j=0 if the topmost cell of the jj-th column is empty.

In other words, the ii-th row starts exactly with r_ir\_i full cells. Similarly, the jj-th column starts exactly with c_jc\_j full cells.

These are the rr and cc values of some 3×43 \times 4 grid. Black cells are full and white cells are empty.

You have values of rr and cc. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of rr and cc. Since the answer can be very large, find the answer modulo 1000000007,(109+7)1000000007\\,(10^{9} + 7). In other words, find the remainder after division of the answer by 1000000007,(109+7)1000000007\\,(10^{9} + 7).

입력

The first line contains two integers hh and ww (1≤h,w≤1031 \le h, w \le 10^{3}) --- the height and width of the grid.

The second line contains hh integers r_1,r_2,…,r_hr\_{1}, r\_{2}, \ldots, r\_{h} (0≤r_i≤w0 \le r\_{i} \le w) --- the values of rr.

The third line contains ww integers c_1,c_2,…,c_wc\_{1}, c\_{2}, \ldots, c\_{w} (0≤c_j≤h0 \le c\_{j} \le h) --- the values of cc.

출력

Print the answer modulo 1000000007,(109+7)1000000007\\,(10^{9} + 7).

힌트

In the first example, this is the other possible case.

In the second example, it's impossible to make a grid to satisfy such rr, cc values.

In the third example, make sure to print answer modulo (109+7)(10^9 + 7).

예제3

  1. 예제 1

    입력
    3 4
    0 3 1
    0 2 3 0
    
    예상 출력
    2
    
  2. 예제 2

    입력
    1 1
    0
    1
    
    예상 출력
    0
    
  3. 예제 3

    입력
    19 16
    16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12
    6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4
    
    예상 출력
    797922655