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:
where k is a positive integer.
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
Subtask 1: 10 points
 1 ≤ k ≤ 3000
Subtask 2: 90 points
 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:  ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.4, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC 
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. 