Given the first k terms and coefficients of a linear recurrence and a huge index N, compute the N-th term modulo 104857601.
You are writing a random number generator (RNG) for a lottery auto-submit program. The generator builds a sequence AAA from the linear recurrence below.
Ai=(Ai−1C1+Ai−2C2+⋯+Ai−kCk) mod 104857601(i>k)A_i = (A_{i-1} C_1 + A_{i-2} C_2 + \cdots + A_{i-k} C_k) \bmod 104857601 \qquad (i > k)Ai=(Ai−1C1+Ai−2C2+⋯+Ai−kCk)mod104857601(i>k)
Given kkk and NNN, the initial terms A1,A2,…,AkA_1, A_2, \ldots, A_kA1,A2,…,Ak, and the coefficients C1,C2,…,CkC_1, C_2, \ldots, C_kC1,C2,…,Ck, write a program that computes ANA_NAN.
The first line contains kkk and NNN, separated by a space. (1≤k≤300001 \le k \le 300001≤k≤30000, 1≤N≤10181 \le N \le 10^{18}1≤N≤1018)
The second line contains A1,A2,…,AkA_1, A_2, \ldots, A_kA1,A2,…,Ak, separated by spaces.
The third line contains C1,C2,…,CkC_1, C_2, \ldots, C_kC1,C2,…,Ck, separated by spaces. (0≤Ai,Ci<1048576010 \le A_i, C_i < 1048576010≤Ai,Ci<104857601)
Print ANA_NAN on the first line. ANA_NAN is always smaller than 104857601.