Random Number Generator

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
You may know how to write a random number generator (RNG) after solving this problem (SEAPROAR).
Another way to write a RNG is to use linear recurrence relation. e.g. let's consider the following linear recurrence:
You are given initial values A_{1}, A_{2}, ..., A_{k} and the coefficients C_{1}, C_{2}, ..., C_{k}. Then the RNG can be used to generate any A_{i} for i larger than k.
Your task is to calculate A_{N} for a given N.
Input
There is exactly one test case in each test file.
The first line of input contains two spaceseparated integers k and N as described in the statement. The second line contains k spaceseparated integers A_{1}, A_{2}, ..., A_{k} denoting the initial values as defined in the problem statement. Then the third line contains k spaceseparated integers C_{1}, C_{2}, ..., C_{k}, denoting the coefficients.
Output
Print a single integer denoting value of A_{N}.
Constraints and Subtasks
 1 ≤ N ≤ 10^{18}
 0 ≤ A_{i}, C_{i} < 104857601
 1 ≤ k ≤ 3000
 1 ≤ k ≤ 30000
Example
Input: 3 5 1 2 3 4 5 6 Output: 139
Explanation
A_{1} = 1.
A_{2} = 2.
A_{3} = 3.
A_{4} = (A_{3} × C_{1} + A_{2} × C_{2} + A_{1} × C_{3}) mod 104857601 = (3 × 4 + 2 × 5 + 1 × 6) mod 104857601 = (12 + 10 + 6) mod 104857601 = 28.
A_{5} = (A_{4} × C_{1} + A_{3} × C_{2} + A_{2} × C_{3}) mod 104857601 = (28 × 4 + 3 × 5 + 2 × 6) mod 104857601 = (112 + 15 + 12) mod 104857601 = 139.
Author:  cgy4ever 
Tester:  laycurse 
Editorial  http://discuss.codechef.com/problems/RNG 
Tags  cgy4ever, fft, hard, march15 
Date Added:  12122014 
Time Limit:  15 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. 