#P174. 二项卷积

二项卷积

Description

Given two sequences a0,,an,b0,,bma_0, \dots, a_n, b_0, \dots, b_m and a positive integer MM. Calculate an integer sequence c0,,cn+mc_0, \dots, c_{n+m}, satisfying:

$$c_k = \sum_{i=\max(k-m,0)}^{\min(k,n)} \binom k i a_i b_{k-i} \bmod M $$

Here (ki)=k!i!(ki)!\binom k i = \frac{k!}{i!(k-i)!} denotes the binomial coefficient.

Input Format

The first line consists of integer n,m,Mn, m, M.

The second line consists of a0,,ana_0,\dots,a_n.

The third line consists of b0,,bmb_0,\dots,b_m.

Output Format

Print one line, containing c0,,cn+mc_0,\dots,c_{n+m}.

2 5 114
5 1 4
1 9 1 9 8 10
5 46 27 42 100 108 84 42

Limits

For 10%10\% of the test cases, it's guaranteed that n,m103n,m\le 10^3.

For another 20%20\%, MM is a prime.

For another 20%20\%, MM is a power of 22.

For 100%100\% of the test cases, it's guaranteed that $0\le n, m\le 10^5, 2\le M\le 10^9, 0\le a_i, b_j < M$.