AlgoUniversity
  • Go Back
Piggy Bank :

Author

Ayush Kumar Shaw

Difficulty Level : Hard

Submissions : 135

Asked In : Capgemini

Marks :10

: 0 | : 1

Daniel has $$$2$$$ piggy banks. A bigger one and a smaller one. He has divided the bigger piggy bank in $$$n$$$ slots and smaller piggy bank in $$$m$$$ slots, $$$n > m$$$. He has some money deposited in both of them. He chooses $$$m$$$ slots from the bigger piggy bank and transfers their money to $$$m$$$ slots of smaller piggy bank in respective order. He wants that the amount in slot $$$i+1$$$ should always be greater than or equal to that in the slot $$$i$$$, of the smaller piggy bank, after the transfer from the bigger piggy bank. You have to help Daniel to count the number of ways he can transfer the money. Since, the number of ways can be large output it modulo $$$10^9+7$$$.

Input

The first line contains $$$2$$$ integers $$$n,m(1 \leq m < n \leq 1000)$$$.

The second line contains $$$n$$$ integers $$$a_1,a_2,...,a_n(1 \leq a_i \leq 10^9)$$$, the amounts in the $$$n$$$ slots of the bigger piggy bank.

The next line contains $$$m$$$ integers $$$b_1,b_2,...,b_m(1 \leq b_i \leq 10^9)$$$, the amounts in the $$$m$$$ slots of the bigger piggy bank.

Output

Output a single integer - the number of ways Daniel can transfer the money modulo $$$10^9+7$$$.

Example

Input
5 3
9 7 10 3 1
6 7 10
Output
0

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.