LINEAR TRANSFORMATIONS

All submissions for this problem are available.
N people, standing in a circle, numbered 0 to N1, play a game. There is a machine in the center of this circle, configured with a number M, and N coefficients b_0, ...b_{N1}.
Further, initially, each person has a number with him: a_i.
This game is played as follows. In each round, all N players input into the machine, the number that they have (initially a_i).
Given the inputs a_i from all the players, the machine then computes the values c_i = summation (j = 0 to N1) (b_j * a_{i+j}) where a_{i+j} wraps around the circle.
It returns the value (c_i % M) to the i'th player after calculating all c_i values for this round.
This game is further played over multiple rounds with the players now inputting the new numbers into the machine etc.
Given the number of players participating (N),
the value of M (the machine's modulus of calculations),
the initial numbers each player has: a_i,
the N coefficients that the machine uses: b_i
and the number of rounds K,
Find what the numbers that all the players have after the K rounds.
Input
 The first line consists of 2 space separated integers: N and M.
 This is followed by a line containing N integers, the ith of which is the value of a[i].
 This is then followed by a line containing N integers, the ith of which is the value of b[i].
 Finally on a single line, is the value of K, the number of rounds played.
Output
Output N lines, each containing a single integer  the value of the ith player after the K rounds.
Constraints
 N <= 500
 M is prime and < 10^8
 0 <= a_i < M
 0 <= b_i < M
 0 < K < 2^60
Example
Input 1: 5 101 1 2 3 5 8 1 1 0 0 0 3 Output 1: 21 34 43 34 20
Input 1: 3 2 1 0 1 1 0 1 5
Output 1: 1 1 0
Explanation
Input1.
the coefficients mean that each player's next value is the sum of his value and the next person's value, modulo M (c[i] = 1*a[i+0] + 1*a[i+1] % M) after each round.
Hence, the progression of the 5 numbers is as follows:
round 0: 1 2 3 5 8
round 1: 3 5 8 13 9
round 2: 8 13 21 22 12
round 3: 21 34 43 34 20Input 2.
c[i] = (a[i+0] + a[i+2]) % 2 (assuming i+2 wraps around). So here, the progression of rounds is as follows:
round 0: 1 0 1
round 1: 0 1 1
round 2: 1 1 0
round 3: 1 0 1
round 4: 0 1 1
round 5: 1 1 0
Author:  karthikv1392 
Tags  karthikv1392 
Date Added:  1032013 
Time Limit:   1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 