Integer Sequence

Given x, y, the last two digits of A0 and A1, and a large index n, print the last two digits of An where An = x*An-1 + y*An-2.

Medium5MathDynamic programmingSimulationBit manipulationInterviewNo attempts yetTime limit0.25sMemory limit512 MB

Problem

There is a sequence of non-negative integers A0,A1,A2,A3,A_0, A_1, A_2, A_3, \ldots.

For every n2n \ge 2, the sequence satisfies An=x×An1+y×An2A_n = x \times A_{n-1} + y \times A_{n-2}.

Given the last two digits of A0A_0 and A1A_1, write a program that finds the last two digits of AnA_n.

For example, if x=y=1x = y = 1, A0=0A_0 = 0, and A1=1A_1 = 1, the sequence is 0,1,1,2,3,5,8,13,21,34,55,0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, \ldots. The last two digits of A10A_{10} are 5555.

Input

The first line contains xx, yy, a0a_0, a1a_1, and nn, separated by spaces. (1x,y991 \le x, y \le 99, 0n<1080 \le n < 10^8)

a0a_0 and a1a_1 are the last two digits of A0A_0 and A1A_1, respectively. They are always written with two digits; a value below 10 has a leading zero, as in 07.

Output

Print the last two digits of AnA_n. Always print exactly two digits: if the value is below 10, add a leading zero, as in 07.