P17258 [HackerEarth] View Russian Translation
普及
题目描述

View Russian Translation

Egor is a successful freelance software engineer. He is about to get paid for n projects he has recently finished working on. The cost of the i'th project is S_i credits. Egor will be getting money for the projects according to the order, i.e. first he will get S_1 credits, then S_2 credits and so on.

Egor likes to get paid in cash. There are k banknotes available in his city, the cost of the i'th banknote is W_i credits. There is an unlimited amount of each banknote and it's possible to represent any non-negative integer S as some banknote multiset.

Egor has a wallet to keep all the money he has earned. You may think of the wallet as of a banknote sequence. Egor likes to keep the banknotes in his wallet in the non-decreasing order of their costs.

In the beginning, the wallet is empty. Then, each of S_i is represented as a banknote multiset X_i. Egor calls a sequence X_1, X_2, ..., X_n an effortless way of getting paid if for each i it's possible to put all the banknotes from X_i as a subsegment into the current wallet (formed by inserting X_1, X_2, ..., X_{i - 1} in the same way) so that the banknotes in his wallet are in the non-decreasing order of their costs.

For example, if the current wallet is [1, 1, 4, 5, 6], then it's possible to insert X_i = {1, 2, 3, 4} the way Egor wants and it's impossible to do the same with X_i = {1, 2, 3, 4, 5} since the 4 from the wallet doesn't allow to do so.

Your task is calculate the number of effortless ways of getting paid. Two ways are distinct if they aren't equal as sequences of multisets X_1, X_2, ..., X_n.

Input format
The first line of the input contains an integer t denoting the number of test cases.

The first line of the test case description contains two integers n and k. The next line contains k integers denoting W_1, W_2, ..., W_k. The next line contains n integers denoting S_1, S_2, ..., S_n.

Output format
The output should contain a single integer denoting the number of effortless way of getting paid modulo 1000000009 (10^9 + 9).

Constraints

1 ≤ t ≤ 6
1 ≤ n ≤ 100
1 ≤ k ≤ 10
1 = W_1 < W_2 < ... < W_k ≤ 5000
1 ≤ S_i ≤ 5000

SAMPLE INPUT
1
2 3
1 5 10
6 11

SAMPLE OUTPUT
7

Explanation

There are two ways to represent S_1 = 6: {1, 1, 1, 1, 1, 1} and {1, 5}. There are also four ways to represent S_2 = 11: {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 5}, {1, 5, 5} and {1, 10}.

There are $8 = 2 \times 4$ possible combinations of representations, but one of them is invalid: X_1 = {1, 5} and X_2 = {1, 10} is not an effortless way of getting paid.

输入格式

见题面

输出格式

见题面

样例输入
6 5 1 1 337 2063 3426 593 2536 5 2 1 2 1540 388 4871 4616 1552 100 10 1 2 3 5 7 12 23 42 60 138 2542 3176 1315 2765 1362 2949 226 1693 4176 2026 4883 1962 4641 1292 3207 3355 2926 76 2868 1773 4481 1738 4282 2605 3677 368 1995 2429 2423 3089 613 3700 3873 1701 4385 1866 3660 3526 4799 2753 1494 1571 1872 2602 4736 3927 4463 3708 1058 2788 3160 1735 3331 3884 3707 2054 80 950 3742 4029 3489 3633 3085 4157 4543 1609 1441 1809 443 1270 3398 2699 2164 3764 1321 2990 182 4631 2298 2106 517 4214 4090 3706 3537 4759 2881 3220 525 651 797 3608 3284 835 2970 2345 1748 1839 3281 4121 100 10 1 2 4 5 9 14 21 47 85 173 558 2635 3157 3153 2770 2367 2659 3246 1359 1624 82 2780 4845 410 1808 2942 3826 3040 1242 1342 818 2385 2215 4791 1947 892 410 4999 2350 2137 2792 2683 4745 3822 635 3548 178 1786 4777 2324 4830 1978 4312 4768 3756 3502 4663 225 958 1087 554 4470 3045 3372 4463 2806 3775 4576 2284 545 4906 1363 3008 177 67 817 3090 953 4698 4289 2955 2074 3605 2879 1803 1075 4953 4969 4091 4337 1209 326 4980 4028 4596 1710 2692 552 2652 624 98 3835 3171 4696 644 4961 4326 4122 2814 3576 100 10 1 2 3 5 8 10 27 28 29 69 4021 4756 4717 4452 4315 4987 4567 4488 4609 4132 4759 4426 4055 4216 4391 4346 4679 4341 4031 4619 4101 4690 4057 4658 4722 4478 4842 4182 4678 4448 4762 4318 4645 4652 4310 4421 4882 4595 4751 4445 4713 4841 4987 4151 4506 4297 4230 4439 4628 4830 4396 4111 4070 4876 4323 4543 4015 4508 4672 4024 4534 4194 4980 4492 4916 4364 4327 4787 4545 4122 4787 4206 4681 4143 4389 4905 4161 4572 4659 4051 4526 4019 4410 4766 4409 4679 4977 4400 4941 4314 4334 4308 4556 4296 4992 4964 4101 4131 4586 4698 100 10 1 2 3 4 7 14 28 57 80 136 4318 4798 4918 4291 4363 4895 4745 4672 4976 4338 4569 4463 4492 4819 4465 4405 4172 4631 4324 4882 4413 4855 4689 4658 4864 4944 4601 4458 4094 4894 4213 4769 4078 4226 4426 4143 4485 4045 4509 4198 4300 4831 4759 4895 4180 4296 4142 4210 4100 4881 4977 4144 4284 4616 4336 4204 4623 4563 4900 4749 4760 4910 4351 4735 4620 4835 4454 4713 4569 4710 4442 4130 4421 4445 4482 4047 4294 4282 4902 4382 4415 4971 4604 4956 4969 4702 4983 4938 4387 4062 4889 4739 4903 4669 4760 4075 4636 4054 4358 4359
样例输出
1 367925439 233629795 816143589 134422580 687957122