Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g(n)(x) modulo 109 + 7.

Input

The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.

Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Output

Print the only integer s — the value g(n)(x) modulo 109 + 7.

Examples

Input

3 4 1 1


Output

7


Input

3 4 2 1


Output

25


Input

3 4 3 1


Output

79
# -*- coding: utf-8 -*-


if __name__ == "__main__":
    A, B, n, X = list(map(int, input().strip().split()))
    mod_tmp = 1000000007
    # cache_B = -1
    if A == 1:
        n = n % mod_tmp
        cache_B = n
    else:
        # if n > mod_tmp:
        #     n = mod_tmp + 1
        # cache_B = int(((pow(A, n, mod_tmp) - 1) % mod_tmp)//((A - 1) % mod_tmp))
        niyuan = pow(A-1, mod_tmp-2, mod_tmp)
        # niyuan = get_niyuan(pow(A, n), A-3, A-1)
        # print(niyuan)
        # print((pow(3, 2, mod_tmp) - 1) * niyuan % mod_tmp)
        # print(A, n)
        cache_B = (pow(A, n, mod_tmp) - 1) * niyuan % mod_tmp

        # print(cache_B)
    item_B = (B % mod_tmp * (cache_B % mod_tmp)) % mod_tmp
    # print(item_B)
    # result = ((A ** n) % mod_tmp) * (X % mod_tmp) + (item_B) % mod_tmp
    result = pow(A, n, mod_tmp) * (X % mod_tmp) + (item_B) % mod_tmp
    result = result % mod_tmp
    print(int(result))
    # print(pow(2, 10**9+7, mod_tmp) * 6 - 5)
    # print(int((pow(3, 10**9+6)-1)/2))
    # temp = (3.5 * pow(3, (10**9+6)) - 2.5) % mod_tmp
    # print(temp)
    
# 1 1 1000000006 1, 0
# 3 1 1000000006 1, 500000003
# 3 5 1 2, 11
# 3 5 2 2, 38
# 2 5 1 1, 7
# 2 5 2 1, 19
# 2 5 999999999 1, 421874998
# 2 5 10000000000 1, 800288104
# 2 5 1000000007 1, 7
# 2 5 1000000008 1, 19

	 	  				 	  	  	  						 		