A sequence of pseudorandom numbers X_1, X_2, \ldots, X_i, \ldots is generated as follows: the numbers X_1, X_2, \ldots, X_k are given explicitly, and each subsequent number is computed by the formula:
You are required to write a program that computes the -th number of this sequence.
The input file contains integers in the following order: (1 \le k \le 30), (1 \le m \le 1000), a_1, \ldots, a_k (0 \le a_i < m), (0 \le b < m), X_1, \ldots, X_k (0 \le X_i < m), (1 \le N \le 10^{100}). The numbers are separated by spaces and/or newline characters.
Output a single number: X_N.
Esempio 1