{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv\u003e\"It is so sweet to have chocolates on St. Valentine\u0027s Day!\" Little Facer was so excited when he receives a box of self-made chocolates from his girlfriend, and he decided to eat these chocolates in a special way to commemorate this important day. Suppose that there are \u003ci\u003eN\u003c/i\u003e types of chocolates in the box, it can be easily calculated that there are totally \u003cimg src\u003d\"CDN_BASE_URL/316eacbc9c7ded81b53acd1bfbecc8f5?v\u003d1714404231\" alt\u003d\"{{n}\\choose{3}}\" align\u003d\"absmiddle\"\u003e different combinations if we choose 3 chocolates of different types to make a dish. Facer will first make one dish for every of these combination, so there will be \u003cimg src\u003d\"CDN_BASE_URL/316eacbc9c7ded81b53acd1bfbecc8f5?v\u003d1714404231\" alt\u003d\"{{n}\\choose{3}}\" align\u003d\"absmiddle\"\u003e dishes in all with 3×\u003cimg src\u003d\"CDN_BASE_URL/316eacbc9c7ded81b53acd1bfbecc8f5?v\u003d1714404231\" alt\u003d\"{{n}\\choose{3}}\" align\u003d\"absmiddle\"\u003e chocolates totally. Then both Facer and his girlfriend choose some chocolates of different types as their original chocolates set. After that, Facer choose exactly \u003ci\u003eM\u003c/i\u003e dishes of three-type-mixed-chocolates which he made in the first step and add them into his original chocolates set. Finally, Facer continues eatting two chocolates of the same type until he cannot find any pair of chocolates of the same type (which means for each type of chocolates, there remains at most one chocolate). Facer wishes that his remaining chocolates set could be identical with his girlfriend\u0027s original chocolates set after the steps mentioned above, but he does not know the number of ways to choose dishes. Could please tell him the answer? \u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cdiv\u003eThe input consists of multiple test cases. Each test case starts with two integers, \u003ci\u003eN\u003c/i\u003e and \u003ci\u003eM\u003c/i\u003e, which are the number of different types of chocolates and the number of three-type-mixed-chocolates dishes Facer will choose, it is guaranteed that 1≤\u003ci\u003eN\u003c/i\u003e≤1000, 0≤\u003ci\u003eM\u003c/i\u003e≤1000. The following two lines contain one \u003ci\u003eN\u003c/i\u003e-bit binary integer each, which represents Facer\u0027s and his girlfriend\u0027s original chocolates set. A case with \u003ci\u003eN\u003c/i\u003e\u003d0 and \u003ci\u003eM\u003c/i\u003e\u003d0 indicates the end of the input file, which should not be processed. \u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cdiv\u003eFor each test case, print one line containing one single integer, which represents the total number of ways to choose dishes. Since the number can be extremely big, you are only required to output the answer % 10007. \u003c/div\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4 3\r\n1101\r\n1001\r\n3 1\r\n101\r\n010\r\n5 3\r\n11010\r\n10111\r\n0 0\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n1\r\n6\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"This problem is inspired from 2008 Regional Hangzhou but is more difficult.\r\u003cbr\u003eA naive print-table-algorithm will not pass. "}}]}