Recursion - 3#330

Recursion - 3

1 second
128 megabytes
Easy (≈1000)

Implement the recursive function for given a, b, c values:

f(n) = \begin{cases} 0, & n < 0 \\ a, & n = 0 \\ f(n - 1) + b \cdot f(n - 2) + c, & n > 0 \end{cases}

Input

Four non-negative integers a, b, c~(a, b, c \leq 1000), n~(0 \leq n \leq 1000) are given.

Output

Output the value of modulo 10^9 + 7.

Examples

Example 1

Loading
Loading