Coloring

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

You will color an array consisting of NN cells numbered 11 to NN for the array game party.

In the attic, there are two types of crayons, A and B, and MM bags for each type, which the ii-th bag has crayons with color ii.

In each bag, there are several crayons having pairwise different thicknesses.

You have to color the cells like the following:

  • First, choose two crayon bags, one from type A and the other from B. The color of the crayons in bags from types A and B must be different.
  • Second, open the two bags and use the crayons in them to color the NN cells(in the order of 1,,2,,,, N1, \\, 2, \\, \cdots, \\,  N). Skipping coloring some cells or using multiple crayons to color a single cell is forbidden. You can use a single crayon as many times as you want.

How many ways are there to color the NN cells? Consider as a different way if at least one of the two bags you chose is different or the crayon you used to color a particular cell has a different type, color, or thickness.

입력

The first line contains two integers NN and MM — the number of cells and the number of bags of each crayon type, respectively.

The second line contains MM integers A_1,,A_2,,,,A_MA\_1, \\, A\_2, \\, \cdots, \\, A\_M, where A_iA\_i is the number of crayons in the ii-th bag of type A.

The third line contains MM integers B_1,,B_2,,,,B_MB\_1, \\, B\_2, \\, \cdots, \\, B\_M, where B_jB\_j is the number of crayons in the jj-th bag of type B.

출력

Print the number of ways to color the NN cells, modulo 109+710^9+7.

제한

  • 1N3×1021 \le N \le 3 \times 10^2
  • 1M1051 \le M \le 10^5
  • 1A_i,,B_j1091 \le A\_i, \\, B\_j \le 10^9 (1i,,jM1 \le i, \\, j \le M)
  • All values in input are integers.