#ARC059C. [ARC059E] キャンディーとN人の子供

[ARC059E] キャンディーとN人の子供

Score : 800800 points

Problem Statement

12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience.

There are NN children in AtCoder Kindergarten, conveniently numbered 11 through NN. Mr. Evi will distribute CC indistinguishable candies to the children.

If child ii is given aa candies, the child's happiness will become xiax_i^a, where xix_i is the child's excitement level. The activity level of the kindergarten is the product of the happiness of all the NN children.

For each possible way to distribute CC candies to the children by giving zero or more candies to each child, calculate the activity level of the kindergarten. Then, calculate the sum over all possible way to distribute CC candies. This sum can be seen as a function of the children's excitement levels x1,..,xNx_1,..,x_N, thus we call it f(x1,..,xN)f(x_1,..,x_N).

You are given integers Ai,Bi(1iN)A_i,B_i (1 \leq i \leq N). Find

modulo 109+710^9+7.

Constraints

  • 1N4001 \leq N \leq 400
  • 1C4001 \leq C \leq 400
  • 1AiBi400(1iN)1 \leq A_i \leq B_i \leq 400 (1 \leq i \leq N)

Partial Score

  • 400400 points will be awarded for passing the test set satisfying Ai=Bi(1iN)A_i=B_i (1 \leq i \leq N).

Input

The input is given from Standard Input in the following format:

NN CC

A1A_1 A2A_2 ... ANA_N

B1B_1 B2B_2 ... BNB_N

Output

Print the value of

modulo 109+710^9+7.

2 3
1 1
1 1
4

This case is included in the test set for the partial score, since Ai=BiA_i=B_i. We only have to consider the sum of the activity level of the kindergarten where the excitement level of both child 11 and child 22 are 11 (f(1,1)f(1,1)).

  • If child 11 is given 00 candy, and child 22 is given 33 candies, the activity level of the kindergarten is 1013=11^0*1^3=1.
  • If child 11 is given 11 candy, and child 22 is given 22 candies, the activity level of the kindergarten is 1112=11^1*1^2=1.
  • If child 11 is given 22 candies, and child 22 is given 11 candy, the activity level of the kindergarten is 1211=11^2*1^1=1.
  • If child 11 is given 33 candies, and child 22 is given 00 candy, the activity level of the kindergarten is 1310=11^3*1^0=1.

Thus, f(1,1)=1+1+1+1=4f(1,1)=1+1+1+1=4, and the sum over all ff is also 44.

1 2
1
3
14

Since there is only one child, child 11's happiness itself will be the activity level of the kindergarten. Since the only possible way to distribute 22 candies is to give both candies to child 11, the activity level in this case will become the value of ff.

  • When the excitement level of child 11 is 11, f(1)=12=1f(1)=1^2=1.
  • When the excitement level of child 11 is 22, f(2)=22=4f(2)=2^2=4.
  • When the excitement level of child 11 is 33, f(3)=32=9f(3)=3^2=9.

Thus, the answer is 1+4+9=141+4+9=14.

2 3
1 1
2 2
66

Since it can be seen that f(1,1)=4,f(1,2)=15,f(2,1)=15,f(2,2)=32f(1,1)=4 , f(1,2)=15 , f(2,1)=15 , f(2,2)=32, the answer is 4+15+15+32=664+15+15+32=66.

4 8
3 1 4 1
3 1 4 1
421749

This case is included in the test set for the partial score.

3 100
7 6 5
9 9 9
139123417