#00004E

z-funkcija

Mr. Little Z is again given a hard math problem for rookies.


The task is: you are given a recursively defined array, so Fn = A* Fn-1 + B* Fn-2 + []* Fn-3


In other words, you are given the constants A, B, C, and values of the array F1 , F2 , F3 .


Help Mr. Little Z find the value of the array ( Fn ) for the given number n.


InputThe first line of the standard input contains three numbers F1 , F2 and F3 that represent values of the array for n=1, 2, 3. Each of the numbers are from the interval [0, 10000]. The second line of the standard input contains three numbers C, B, A. Every number is from the interval [0, 10000]. Finally, the third line contains an integer N from the interval [1, 2000000000].

OutputTo the standard output in one line write the value of Fn modulus 10000. ( FN mod 10000).

Input:
[c]1 1 1
1 1 1
5

Output:
5
Explanation:
From the input we have A=B=[]=1 and F1 = F2 = F3 =1. So F4 = F3 + F2 + F1 =3; and F5 = F4 + F3 + F2 =5

Input:[c]0 1 2
3 2 1
2

Output:
1
Explanation: In this case A=1, B=2, C=3; F1 =0, F2 =1, F3 =2. So we just output F2 =1;

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.