Linear Transformations

All submissions for this problem are available.
Problem description.
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
 0 ≤ a_i < M
 0 ≤ b_i < M
 0 < K < 2^60
Example
Input: Sample Input 1: 5 101 1 2 3 5 8 1 1 0 0 0 3 Sample Input 2: 3 2 1 0 1 1 0 1 5 Output: Sample Output 1: 21 34 43 34 20 Sample Output 2: 1 1 0
Explanation
In the first case, 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 20
In the second case, 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:  himanshu200 
Tags  himanshu200 
Date Added:  14032013 
Time Limit:  0.46 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, 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, 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. 