Modular Knapsack

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

문제

Today you should solve unusual knapsack problem. You are given nn items, ii-th of them has weight w_iw\_i and cost c_ic\_i. Also a prime pp is given. For every remainder rr modulo pp you should find the maximum total cost of a set of items with total weight having remainder rr modulo pp. All weights and costs in each test except samples are chosen randomly and independently from range \[0109]\[0 \dots 10^9]. nn and pp are chosen manually.

입력

The first line contains two integers nn, pp (1n106,2p30001\leq n\leq 10^6, 2\leq p\leq 3000) -- the number of items and the prime modulo.

The next line contains nn integers w_iw\_i (0w_i1090\leq w\_i\leq 10^9) --- the weights of items.

The next line contains nn integers c_ic\_i (0c_i1090\leq c\_i\leq 10^9) --- the costs of items.

출력

Output one line with pp integers. ii-th of them (00-indexed) should be equal to the maximum total cost of a set of items with total weight having remainder ii modulo pp, or 1-1 if such set doesn't exist.