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
import sys

MOD = 10**9 + 7


def super_power(A, n, m):
    if n == 1:
        return A
    if n % 2 == 0:
        res = super_power(A, n/2, m)
        return res ** 2 % m
    else:
        res = super_power(A, (n - 1)/2, m)
        return (((res ** 2) % m) * A) % m

def ext_gcd(x, y):
    if x == 0:
        return y, 0, 1
    value, a, b = ext_gcd(y % x, x)
    return value, b - (y / x)*a, a


# ax + by = value
# y%x * a1 + x*b1 = value
# y % x = y - (y/x*x)
# (y - (y/x)*x) * a1 + x * b1 = value
# y * a1 + x(b1 - y/x) = value
# b = a1
# a = b1 - y/x

def super_inverse(A, m):
    inverse = ext_gcd(A, m)[1]
    if inverse < 0:
        return inverse + m
    return inverse

def super_substr(a, b, m):
    result = (a % m - b % m)
    if result < 0:
        return result + m
    return result

def super_mul(a, b, m):
    return ((a % m) * (b % m)) % m

def geom_sum(power, p, q, b1):
    if q == 1:
        return (power * b1) % MOD

    up = super_mul(b1, super_substr(1, p, MOD), MOD)
    down = super_inverse(super_substr(1, q, MOD), MOD)
    return up * down % MOD


if __name__ == "__main__":
    A, B, n, x = [int(i) for i in sys.stdin.readline().strip().split()]
    power = super_power(A, n, MOD)

    print (power * x + B * geom_sum(n, power, A, 1)) % MOD




