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
a, b, n, x = map(int, raw_input().split())
m = 10 ** 9 + 7 

def pow_mod(x, n, m):
  if n == 0:
    return 1
  y = pow_mod(x, n // 2, m)
  y = (y * y) % m
  if n % 2 == 1:
    y = (x * y) % m
  return y

def extended_euclid(a, b):
  r0, s0, t0 = a, 1, 0
  r1, s1, t1 = b, 0, 1
  while r1 != 0:
    q = r0 // r1
    r0, r1 = r1, r0 - q * r1
    s0, s1 = s1, s0 - q * s1
    t0, t1 = t1, t0 - q * t1
  return r0, s0, t0

def div_mod(a, b, m):
  inverse = extended_euclid(b, m)[1]
  #print('inverse of %d mod %d = %d' % (b, m, inverse))
  return (a * inverse) % m

p = pow_mod(a, n, m)
if a == 1:
  y = n
else:
  y = div_mod(p - 1, a - 1, m)
#print(x, y)

result = (p * x + y * b) % m
print(result)

