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.

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.

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

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

line = raw_input()

A, B, n, x = line.split()
mod = 1000000007

def matmult(a, b):
	return [
		a[0]%mod*b[0]%mod+a[1]%mod*b[2]%mod,
		a[0]%mod*b[1]%mod+a[1]%mod*b[3]%mod,
		a[2]%mod*b[0]%mod+a[3]%mod*b[2]%mod,
		a[2]%mod*b[1]%mod+a[3]%mod*b[3]%mod
		]

a0 = [int(A), 1, 0, 1]

def modpow(a, b):
	if b == 1:
		return a0
	elif b & 1 == 1:
		return matmult(a0, modpow(a,b-1))
	else:
		x = modpow(a, b/2)
		return matmult(x, x)

an = modpow(a0, int(n))
print (an[0]*int(x)+an[1]*int(B))%mod

import sys,math
def power(x, y, p):
    res = 1;
    x = x % p;
    while (y > 0):
        if (y & 1):
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    return res;
def modInverse(b,m):
	g = math.gcd(b, m)
	if (g != 1):
		return -1
	else:
		return pow(b, m - 2, m)
def modDivide(a,b,m):
	a = a % m
	inv = modInverse(b,m)
	if(inv == -1):
		print("Division not defined")
	else:
		return (inv*a) % m
#using sum of GP series
A,B,n,X=map(int,sys.stdin.readline().split())
m=10**9+7
if A==1:
    print(((n%m)*B+X)%m)
else:
    temp=power(A,n,m)
    s=(temp*(X%m))%m
    s=(s%m+((modDivide(B*(temp-1),A-1,m)%m)%m)%m)%m
    print(s%m)

mod=10**9+7
def ans(n,a,b):
    if n==0:
        return 1,0
    elif n==1:
        return a,b
    elif n%2==1:
        p,q=ans(n-1,a,b)
        return (a*p)%mod,(a*q+b)%mod
    else:
        p,q=ans(n/2,a,b)
        return (p*p)%mod,(p*q+q)%mod
a,b,n,x=map(int,raw_input().split())
p,q=ans(n,a,b)
print (x*p+q)%mod

a,b,n,x=map(int,raw_input().split())
mod=10**9+7
if a==1:
  print (x+n*b)%mod
else:

  print (pow(a,n,mod)*x+b*(pow(a,n,mod)-1)*(pow(a-1,mod-2,mod))+mod)%mod

#!/usr/bin/env python3

def g(a, b, n, x, mod=10 ** 9 + 7):
    if a == 1:
        return (x + b * n) % mod
    z = pow(a, n, mod)
    inv = pow(a - 1 + mod, mod - 2, mod)
    return (z * x + b * (z - 1 + mod) * inv) % mod

print(g(*[int(x) for x in input().split()]))

A, B, n, x = map(int, input().split())
MOD = 10 ** 9 + 7

def SD(i):
    if i == 0:
        return 1
    elif i % 2 == 0:
        return (1 + A * SD(i - 1)) % MOD
    else:
        md = pow(A, i // 2 + 1, MOD)
        return ((md + 1) * SD(i // 2)) % MOD

res = pow(A, n, MOD) * x + SD(n - 1) * B
print(res % MOD)

#!/usr/bin/python
import sys
import re

def input_numbers():
    return [int(n) for n in raw_input().split()]

A,B,n,x = input_numbers()
MOD = 10 ** 9 + 7

def mul(m1, m2):
    a,b,c,d = m1[0][0], m1[0][1], m1[1][0], m1[1][1]
    x,y,z,w = m2[0][0], m2[0][1], m2[1][0], m2[1][1]
    return (((a*x + b*z) % MOD, (a*y + b*w) % MOD), ((c*x + d*z) % MOD, (c*y + d*w) % MOD))

def square(m):
    return mul(m, m)

def power(m, n):
    if n == 0:
        return ((1, 0), (0, 1)) #Id
    sq = power(square(m), n / 2)
    if n % 2 == 1:
        sq = mul(m, sq)
    return sq

m = ((A, 0), (B, 1))
mn = power(m, n)

A,B = mn[0][0], mn[1][0]
print (A*x + B) % MOD

from sys import stdin

mod = 10**9+7

def geo(x, n, m):
    return (pow(x, n+1, m) - 1)*pow(x-1, m-2, m)

p, q, n, a = [int(x) for x in stdin.readline().rstrip().split()]
if p <= 1:
    print((a + q * n) % mod)
else:
    ans = (a * pow(p, n, mod) + q * (geo(p, n-1, mod) % mod)) % mod
    print(ans)

mod = 10**9 + 7

def pow(num, p):
    global mod
    if p == 1:
        return num
    ans = pow(num, p//2)
    if p % 2 == 0:
        return ans * ans % mod
    else:
        return ans * ans * num % mod

A, B, n, x = tuple(map(int, input().split()))

if A != 1:
    ans = B
    ans *= ((pow(A, n) - 1) % mod * (pow(A-1, mod - 2) % mod)) % mod
    ans += pow(A, n) * x % mod
    ans %= mod
else:
    ans = x + n * B
    ans %= mod

print(round(ans))

import sys
def main():
	for line in sys.stdin:
		line = line.split()
		A = int(line[0])
		B = int(line[1])
		n = int(line[2])
		x = int(line[3])
		mod = 1000000007
		if(A==1):
			asum = n
		else:
			num = pow(A,n,mod*(A-1))
			asum = ((pow(A,n,mod*(A-1))-1)//(A-1))%mod
		print((B*asum%mod + x*pow(A,n,mod))%mod)

if __name__ == "__main__":
   main()

#A(A(Ax + B) + B) +B

#B(1+A+A^2+...+A^(n-1))+x*A^n

#B(A^n -1)/(A-1) + x*A^n

#For test case 1000 2000 50 20
#826144502

MOD=10**9+7
a,b,n,x=map(int,input().split())
t=pow(a,n,MOD*max(1,a-1))
print((t*x+b*(t-1)//(a-1))%MOD if a-1else(x+n*b)%MOD)

import math
def modInverse(b,m):
    g = math.gcd(b, m)
    if (g != 1):
        return -1
    else:
        return pow(b, m - 2, m)
def modDivide(a,b,m):
    a = a % m
    inv = modInverse(b,m)
    return (inv*a)%m
mod=int(10e8+7)
a,b,n,x=map(int,input().split())
if a==1:
    print((x%mod+(n*b)%mod)%mod)
    exit()
exp=a
ans=1
while n>0:
    if(n%2==1):
        ans=(ans*exp)%mod
    exp=(exp*exp)%mod
    n//=2
res=(ans-1)%mod
res=modDivide(res,a-1,mod)
print(((ans*x)%mod+(res*b)%mod)%mod)

import sys

mod = int(1000000007)
def inv(a):
    a1 = pow(a, mod-2, mod)
    return a1
A, B, n, x = map(int, raw_input().split(' '))
A, B, n, x = [int(A), (int)(B), (int)(n), (int)(x)]
#print A,B, n, x

if A != 1:
    A_n = pow(A, n, mod)
    rev = inv(A-1)
    p1 = (A_n*x)%mod
    p2 = B*((((A_n*rev)%mod)-rev)%mod)
    ans = (p1 + p2)%mod
    print ans
else:
    ans = (x + (B*(n)%mod))%mod
    print ans

# from dust i have come, dust i will be

mod=int(1e9)+7

A,B,n,x=map(int,input().split())

'''
if we expand the given formula for some test cases
e.g-> for n=2,3,4.. we get
A^n*x + B(A^0+A^1+...+A^{n-1})
for the geometric progression, 1+r+r^2+...+r^{n-1}
the ans=(r^n-1)/(r-1) when r>1, if r==1, ans=nr
'''

if n==0:
    print(x)
    exit(0)

if A==1:
    temp=n*A
else:
    '''
    (A/B)%m=(A%m*(B^-1)%m)%m
    '''
    x1=pow(A,n,mod)-1
    x2=pow(A-1,mod-2,mod)
    temp=(x1*x2)% mod

p1=pow(A,n,mod)*pow(x,1,mod)
p1=p1%mod

p2=(B%mod)*temp
p2=p2%mod

print((p1+p2)%mod)

a,b,n,x=map(int,input().split())
m=10**9+7
if a != 1:
    print((pow(a, n, m)*x + b * ((pow(a, n, m) - 1) * pow(a - 1, m - 2, m)))%m)
else:
    print((b*n+x)%m)

#http://codeforces.com/problemset/problem/678/D
def matrixProductModulo(dic1,dic2,modulo):
    dic = {}
    dic['a'] = (dic1['a']*dic2['a'] + dic1['b']*dic2['c'])%modulo
    dic['b'] = (dic1['a']*dic2['b'] + dic1['b']*dic2['d'])%modulo
    dic['c'] = (dic1['c']*dic2['a'] + dic1['d']*dic2['c'])%modulo
    dic['d'] = (dic1['c']*dic2['b'] + dic1['d']*dic2['d'])%modulo
    return dic
def getIdentityMatrix():
    identityMatrix = {}
    identityMatrix['a'] = 1
    identityMatrix['b'] = 0
    identityMatrix['c'] = 0
    identityMatrix['d'] = 1
    return identityMatrix

def binaryExp(dic,power,modulo):
    if power == 0:
        return getIdentityMatrix()
    halfPower = binaryExp(dic,power/2,modulo)
    halfPowerProduct = matrixProductModulo(halfPower,halfPower,modulo)
    if power%2 == 0:
        return halfPowerProduct
    else:
        return matrixProductModulo(dic,halfPowerProduct,modulo)

a,b,n,x = map(int,raw_input().split())
modulo = 10**9 + 7
matrix = {}
matrix['a'] = a
matrix['b'] = b
matrix['c'] = 0
matrix['d'] = 1
matrixPower = binaryExp(matrix,n,modulo)
ans = (matrixPower['a']*x + matrixPower['b'])%modulo
print ans

mod = int(10**9 + 7)
mud = int(10**9 + 6)

def powM(bs, pw, MOD):
    res = 1
    for i in range(pw.bit_length() - 1, -1, -1):
        res = (res * res) % MOD
        if (pw & (1 << i) > 0):
            res = (res * bs) % MOD

    return res

A, B, n, x = raw_input().split()

A = int(A)
B = int(B)
n = int(n)
x = int(x)

if A == 1:
    n %= mod
    print (x + B * n) % mod
else:
    n %= mud
    An = powM(A, n, mod)
    fx = B * (mod + An - 1) % mod * powM(A - 1, mod - 2, mod)
    print (An * x + fx) % mod

a,b,n,x=map(int,input().split())
m=10**9+7
print(((pow(a,n,m)*x+b*(pow(a,n,m)-1)*pow(a-1,m-2,m)) if a!=1 else b*n+x)%m)

a, b, n, x = map(int, input().split())
m = 10 ** 9+7
# modular multiplicative inverse in second power
print(((pow(a,n,m)*x+b*(pow(a,n,m)-1)*pow(a-1,m-2,m)) if a!=1 else b * n + x)%m)

a, b, n, x = map(int, raw_input().split())
mod = 10**9+7
print (pow(a, n, mod) * x + b * (n if a == 1 else (pow(a, n, mod) - 1) * pow(a - 1, mod - 2, mod))) % mod

a,b,n,x=map(int,raw_input().split())
mod=1000*1000*1000 +7
sum=0
if(a==1):
    sum=(x%mod+n*b%mod)%mod
else:
    sum=(pow(a,n,mod)*x+(((b*(pow(a,n,mod)-1))%mod)*pow(a-1,mod-2,mod))%mod)%mod

print(sum)

import functools
import itertools

class NotAMatrixError(Exception):
    pass

class MatrixSizeError(Exception):
    def __init__(self, s1, s2):
        print('sizes do not match : ', s1, ', ', s2)

class NotSquareError(Exception):
    pass

class Matrix(list):
    def __init__(self, L):
        if type(L) == type(self):
            self = L
            return
        n = len(L)
        m = len(L[0])
        for i in range(n):
            if len(L[i]) != m:
                raise NotAMatrixError()
        list.__init__(self, L)
        self.n = n
        self.m = m
        self.degrees = []
    def check_size(self, M, mode):
        n, m = len(M), len(M[0])
        for i in range(n):
            if len(M[i]) != m:
                raise NotAMatrixError()
        if mode == 'add' and self.n != n or self.m != m:
            raise MatrixSizeError((self.n, self.m), (n,m))
        if mode == 'mul' and self.m != n:
            raise MatrixSizeError((self.n, self.m), (n,m))
    def __add__(self, M):
        self.check_size(M, mode = 'add')
        return Matrix([[self[i][j]+M[i][j] for j in range(self.m)]for i in range(self.n)])
    def __iadd__(self, M):
        self.check_size(M, mode = 'add')
        for i in range(self.n):
            for j in range(self,m):
                self[i][j] += M[i][j]
    def __mul__(self, M):
        self.check_size(M, mode = 'mul')
        l = len(M[0])
        return Matrix([[sum(self[i][k]*M[k][j] for k in range(self.m))
                 for j in range(l)] for i in range(self.n)])
    def issquare(self):
        return self.n == self.m
    def primary(self):
        if self.n != self.m:
            raise NotSquareError()
        return Matrix([[int(i==j) for j in range(self.m)] for i in range(self.n)])
    def __pow__(self, n):
        if self.n != self.m:
            raise NotSquareError()
        if n == 0:
            return self.primary()
        elif n == 1:
            return self
        if len(self.degrees) == 0:
            self.degrees.append(self*self)
        for i in range(n.bit_length() - len(self.degrees) - 1):
            self.degrees.append(self.degrees[-1] * self.degrees[-1])
        s = [(n>>i)&1 for i in range(1,n.bit_length())]
        res = functools.reduce(lambda x,y:x*y, itertools.compress(self.degrees, s))
        return res*self if n%2 else res
    def drop_degrees(self):
        self.degrees.clear()

class RemMatrix(Matrix):
    def __init__(self, L, p):
        Matrix.__init__(self, L)
        self.p = p

    def primary(self):
        if self.n != self.m:
            raise NotSquareError()
        return Matrix([[Remainder(i==j, self.p) for j in range(self.m)] for i in range(self.n)])

    def __mul__(self, M):
        self.check_size(M, mode = 'mul')
        l = len(M[0])
        return RemMatrix([[sum((self[i][k]*M[k][j] for k in range(self.m)),
                            Remainder(0, self.p)) for j in range(l)]
                       for i in range(self.n)], self.p)

class Remainder(tuple):
    def __new__(self, a, n):
        return tuple.__new__(self, (a%n, n))
    def __add__(self, p):
        return Remainder((self[0] + p[0]) % self[1], self[1])
    def __sub__(self, p):
        return Remainder((self[0] - p[0]) % self[1], self[1])
    def __mul__(self, p):
        return Remainder((self[0] * p[0]) % self[1], self[1])
    def __radd__(self, p):
        return Remainder((self[0] + p[0]) % self[1], self[1])
    def __rsub__(self, p):
        return Remainder((self[0] - p[0]) % self[1], self[1])
    def __rmul__(self, p):
        return Remainder((self[0] * p[0]) % self[1], self[1])
    def __neg__(self):
        return Remainder((-self[0]) % self[1], self[1])

p = 10 ** 9 + 7
r = lambda x : Remainder(x, p)

N = map(r, range(10))

a, b, n, x = map(int, input().split())
a1, b1, o, l, x1 = r(a), r(b), r(0), r(1), r(x)
M = RemMatrix([[a1, b1], [o, l]], p)
L = (M ** n)

print((L[0][0] * x1 + L[0][1])[0])

import sys

def r():
	return sys.stdin.readline()

mod = 1000000007

def q(n,a,b):
	if n == 0:
		return 1,0
	if n == 1:
		return a,b
	if n % 2 == 1:
		xa,xb = q(n-1,a,b)
		return a*xa % mod, (a*xb + b) % mod
	else:
		xa,xb = q(n/2,a,b)
		return xa*xa % mod, (xa*xb + xb) % mod

a,b,n,x = map(int, r().split())

xa,xb = q(n,a,b)
print (x*xa+xb) % mod

a,b,n,x = map(int,input().split())
md = 10**9+7
mult  = lambda u,v : 0 if v==0 else (u+mult(u,v-1))%md if v % 2 == 1 else (2*mult(u,v//2))%md
get_prog = lambda a,b,n : mult(pow(a,n,md)-1+md,pow(a-1+md,md-2,md)) if a!=1 else n
res = mult(pow(a,n,md),x)+mult(get_prog(a,b,n),b)
res%=md
print(res)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 16:49:52 2020

@author: shailesh
"""
#def power_sum(A,n):
#    if A == 1:
#        return 1

A,B,n,x = [int(i) for i in input().split()]

#n-=1

m = 10**9 + 7
#val = A**n*x + B*(A**n - 1)//(A-1)
if A != 1:
    val = pow(A,n,m)*x + B*(pow(A,n,m) - 1)*pow(A-1,m-2,m)
else:
    val = (x + n*B)
print(val%(m))

import math
import sys
sys.setrecursionlimit(10000)
def gcd(a, b):
    return b if a % b == 0 else gcd(b, a % b)

def lcm(a, b):
    return a*b/gcd(a,b)

def e_gcd(a, b):
    if (a == 0):
        return 0, 1, b
    x1, y1, d = e_gcd(b % a, a)
    x = y1 - (b / a) * x1
    y = x1
    return x, y, d

s = raw_input()
a, b, n, x = s.split()
a = int(a)
b = int(b)
n = int(n)
x = int(x)

base = int(1e9 + 7)
if a == 1:
    print (x + (n)*b)%base
else:

    res = (pow(a, n, base) * x) % base

    s = (b * (1 - pow(a, n, base))) % base
    s = (s + base) % base

    q = (1 - a) % base + base
    q %= base
    xx, yy, dd = e_gcd(q, base)
    xx = (xx % base + base) % base
    ans = res + s * xx
    print ans % base

a, b, n, x = map(int, input().split())
MOD = 1000000007

cur = x
while n > 0:
    if n & 1:
        cur = (a * cur + b) % MOD
    a, b = a*a % MOD, (a*b + b) % MOD
    n >>= 1
print(cur)

import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int,minp().split())

A,B,n,x = mints()
r = 0
if n == 0:
	r = x
elif A == 1:
	r = x + B*n
else:
	r = (pow(A,n,10**9+7)-1)*pow(A-1,10**9+5,10**9+7)*B+pow(A,n,10**9+7)*x
print(r%(10**9+7))

a, b, n, x = map(int, input().split())
MOD = 10 ** 9 + 7
ans = pow(a, n, MOD) * x
if a > 1:
	tmp = (pow(a, n, MOD) - 1)
	if tmp < 0:
		tmp += MOD
	tmp *= pow(a - 1, MOD - 2, MOD)
	tmp *= b
else:
	tmp = n * b
print((ans + tmp) % MOD)

#!/usr/bin/env python
#-*- coding:utf-8 -*-

import sys, math, random, operator
from string import ascii_lowercase
from string import ascii_uppercase
from fractions import Fraction, gcd
from decimal import Decimal, getcontext
from itertools import product, permutations, combinations
from Queue import Queue, PriorityQueue
from collections import deque, defaultdict, Counter
getcontext().prec = 100

MOD = 10**9 + 7
INF = float("+inf")

if sys.subversion[0] != "CPython":  # PyPy?
    raw_input = lambda: sys.stdin.readline().rstrip()
pr = lambda *args: sys.stdout.write(" ".join(str(x) for x in args) + "\n")
epr = lambda *args: sys.stderr.write(" ".join(str(x) for x in args) + "\n")
die = lambda *args: pr(*args) ^ exit(0)

read_str = raw_input
read_strs = lambda: raw_input().split()
read_int = lambda: int(raw_input())
read_ints = lambda: map(int, raw_input().split())
read_float = lambda: float(raw_input())
read_floats = lambda: map(float, raw_input().split())

"---------------------------------------------------------------"

a, b, n, x = read_ints()

cur = x
while n > 0:
    if n & 1:
        cur = (a * cur + b) % MOD
    a, b = a*a % MOD, (a*b + b) % MOD
    n >>= 1
print cur

import sys
a,b,n,x = map(int,raw_input().split())
mod = 1000000007
if(a is 1):
	print (n*b + x)%mod
else :
	print (pow(a,n,mod)*x + b*(((pow(a,n,mod) - 1)*pow(a - 1,mod - 2,mod)) % mod))%mod

A, B, n, x = map(int, raw_input().split())
MOD = 10**9+7
if A > 1:
    print (x * pow(A, n, MOD) + B * (pow(A, n, MOD)-1) * pow(A-1, MOD-2, MOD)) % MOD
else:
    print (x * pow(A, n, MOD) + B * n) % MOD

import sys

def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())
def input(): return sys.stdin.readline().strip('\n')

a,b,n,x = get_ints()

mod = 10**9 + 7
k = pow(a,n,mod)

#well that was fucking awesome.
if( a != 1):
    ans = ((b%mod)*(((k-1)*pow(a-1,mod-2,mod))%mod)+(k*x)%mod)%mod
    print(ans)
else:
    print( ((k*x)%mod + (n%mod * b%mod)%mod)%mod)

a,b,n,x=map(int,input().split())
mod=(10**9+7)*(a-1)
mod1=(10**9+7)
#print(int(x*(a**n)+b*(a**n-1)/(a-1)))'''
def bin_pow(a,n,mod):
    if n==1:
        return a
    else:
        if n%2==0:
            return ((bin_pow(a,n//2,mod)**2))%mod
        return (((bin_pow(a,n//2,mod)**2)*a))%mod

def s(a,n,b=1):
    ans=0
    for k in range(n):
        ans+=b*(a**k)
    return ans

if a!=1:
    ans=x*bin_pow(a,n,mod)

    ans+=b*(bin_pow(a,n,mod)-1)//(a-1)
    print(int(ans)%mod1)

else:
    ans=x*bin_pow(a,n,mod1)
    ans+=b*n
    print(ans%mod1)

a,b,n,x=map(int,input().split())
m=10**9+7
print(((pow(a,n,m)*x+b*(pow(a,n,m)-1)*pow(a-1,m-2,m)) if a!=1 else b*n+x)%m)

from collections import defaultdict
import sys

def mpow(base, p):
    temp = 1
    while p:
        if (p & 1):
            temp = (temp * base) % MOD
        p //= 2
        base = (base * base) % MOD
    return temp % MOD
if __name__ == "__main__":
    #n, m = list(map(int, input().split()))
    a, b, n, x = map(int, input().split())
    MOD = 10 ** 9 + 7
    temp = mpow(a, n)
    if a > 1:
        ans = ((temp * x % MOD) + (b * (temp - 1) % MOD) * mpow(a - 1, MOD - 2) % MOD) % MOD
    else:
        ans = ((temp * x % MOD) + b * (n % MOD) % MOD) % MOD
    print(ans)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time

(A, B, n, x) = (int(i) for i in input().split())

start = time.time()

md  = 1000000007

if A!=1 :
    an  = pow(A, n, md*(A-1))
    bn  = B*(an-1)//(A-1)
    ans = (an*x+bn)%md
else:
    ans = (x+B*n)%md
print(ans)

finish = time.time()
#print(finish - start)

MOD = 1000000007
A, B, n, x = map(int, raw_input().split())
if A==1:
    print (x%MOD + ((B%MOD * n%MOD)%MOD))%MOD
else:
    print ((pow(A, n, MOD)*(x%MOD))%MOD + (B%MOD * (((pow(A, n, MOD)-1)%MOD) * (pow(A-1, MOD-2, MOD)))%MOD)%MOD)%MOD

def modPow(base, pow, mod):
    ret = 1
    while pow > 0:
        if (pow % 2) == 0:
            base = (base * base) % mod
            pow >>= 1
        else:
            ret = (ret * base) % mod
            pow = pow - 1
    return ret;

a, b, n, x = map(int, raw_input().split())
modulo = 1000000007

first = modPow(a,n,modulo)
second = x % modulo
third = 0
if a != 1:
    third = modPow(a, n, modulo * (a - 1))
    third = modulo * (a - 1) - 1 if third == 0 else third - 1
    third = third / (a - 1) * b
else:
    third = (b * n) % modulo
ans = (((first * second) % modulo) + third % modulo) % modulo
print ans

a,b,n,x=map(int, input().split());
m=1000000007;
def modex(a,n):
	ans=1
	while n:
		if n&1:
			ans=(ans%m*a%m)%m
		a=(a%m*a%m)%m
		n>>=1
	return ans
if a==1:
	print((x%m+(b%m*n%m)%m)%m)
else:
	print(((modex(a,n)%m*x%m)%m+(b%m*((modex(a,n)%m-1%m)%m)%m*(modex(a-1,m-2)))%m)%m)

M = int(1e9 + 7)
A, B, n, x = (int(x) for x in input().split())
if A > 1:
    An = pow(A, n, M)
    print((An * x + B * (1-An) * pow(1-A, M-2, M)) % M)
else:
    print((x + B*n) % M)

a,b,n,x=map(int,raw_input().split())
mod=10**9+7
if a==1:
  print (x+n*b)%mod
else:

  print (pow(a,n,mod)*x+b*(pow(a,n,mod)-1)*(pow(a-1,mod-2,mod))+mod)%mod

import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def inv(a):
    return pow(a, MOD-2, MOD)

a,b,n,x = Ri()
ans = pow(a, n, MOD) * x
if a > 1:
    ans += b * ( pow(a, n, MOD) -1 ) * inv(a-1)
if a == 1:
    ans += (b*(n%MOD))%MOD

print(ans%MOD)

def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def modexp ( g, u, p ):
   """computes s = (g ^ u) mod p
      args are base, exponent, modulus
      (see Bruce Schneier's book, _Applied Cryptography_ p. 244)"""
   s = 1
   while u != 0:
      if u & 1:
         s = (s * g)%p
      u >>= 1
      g = (g * g)%p;
   return s

A,B,n,x=map(int, raw_input().split())
magic=10**9+7
if A==1:
    print (x+n*B)%magic
else:
    An=modexp(A, n, magic)
    Annumerator=(An-1)%magic
    Adenominator=(A-1)%magic
    Adenominator=modinv(Adenominator, magic)
    print ((An*x) % magic+ (((Annumerator*Adenominator)%magic) *B )%magic)%magic

a, b, n, x = map(int, raw_input().split())

mod = 1000000007

cur = x
while n > 0:
    if n & 1:
        cur = (a * cur + b) % mod
    a, b = a * a, a * b + b
    a %= mod
    b %= mod

    n >>= 1

print cur

a, b, n, x = map(int, input().split())
MOD = 1000000007

cur = x
while n > 0:
    if n & 1:
        cur = (a * cur + b) % MOD
    a, b = a*a % MOD, (a*b + b) % MOD
    n >>= 1
print(cur)

from sys import stdin
import sys
sys.setrecursionlimit(10**7)
A,B,n,x=map(int,stdin.readline().strip().split())
mod=10**9+7
"""
dp=[-1 for i in range(n+10)]
def f(x1):
    return (A*x1+B)%mod
def g(n,x):
    if n==0:
        return x
    if dp[n]!=-1:
       return dp[n]
    dp[n]=f(g(n-1,x))
    return dp[n]
"""
def geo(n):
    ans=(pow(A,n,mod)*x)%mod
    if(A!=1):
        ans1=(((B-B*pow(A,n,mod))%mod)*pow(1-A,mod-2,mod))%mod
    else:
        ans1=(B*n)
    return (ans+ans1)%mod
print(geo(n))

from sys import stdin, stderr, stdout, exit
from math import gcd

readl = lambda : list(map(int, stdin.readline().strip().split()))
MOD = 1000000007

def main():
    A, B, n, x = readl()
    if(A == 1):
        stdout.write(str((B*n + x) % MOD))
    else:
        An = pow(A, n, MOD)
        stdout.write(str((((An * x) % MOD) + (B * (1-An) * pow(1-A, MOD-2, MOD)) % MOD) % MOD))

if __name__ == '__main__':
    main()

def extendedEuclidean(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = extendedEuclidean(b % a, a)
        return (g, x - (b // a) * y, y)

def exp_mod (base, exp, mod):
    if (mod == 1):
        return 0;

    number = 1;

    while (exp):
        if (exp & 1):
            number = (number * base) % mod;
        exp >>= 1
        base = (base * base) % mod;

    return number

if __name__ == '__main__':
    a, b, n, x = map(int, raw_input().split())

    m = 1000000007
    s = 0

    an = exp_mod (a, n, m)
    if a == 1:
        s = (n+m)%m
    else:
        p = (an-1)%m
        q = extendedEuclidean(a-1, m)[1]
        q = (q+m)%m
        s = ((p%m)*(q%m))%m
        s = (s+m)%m
        # print s, a, an

    ss = ((an*x)+m)%m + ((b*s)+m)%m

    ss = (ss+m)%m

    print ss

def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

A,B,n,x = map(int,raw_input().split())
m = 10**9 + 7
if n == 0:
    print x%m
elif n == 1:
    print (A*x + B)%m
elif A == 1:
    print (x + B*n)%m
else:
    a = (pow(A,n,m)*x)%m
    b = ((pow(A,n,m)-1)*modinv(A-1,m))%m
    if b < 0: b += m
    print (a + b*B)%m

import sys

def mod_inverse(b,c):
    prod = 1
    while b != 1:
        factor = c/b
        prod = (prod*(factor+1))%c
        b = (factor+1)*b-c
    return prod

def mod_exp(A,n,c):
    max_2 = 1
    A_dict = {0:1,1:A%c,2:(A**2)%c}
    val = (A**2)%c
    power = 2
    while n > power:
        power*=2
        val = (val**2)%c
        A_dict[power] = val
    total = 1
    while n > 0:
        if power <= n:
            n = n - power
            total = (total*A_dict[power])%c
        power = power/2
    return total

def find_value(A,B,n,x):
    A_exp = mod_exp(A,n,10**9+7)
    if A != 1:
        A_less_inv = mod_inverse(A-1,10**9+7)
        A_sum = ((A_exp-1)*(A_less_inv))%(10**9+7)
    else:
        A_sum = n%(10**9+7)
    final_val = (x*A_exp+A_sum*B)%(10**9+7)
    return final_val

if __name__=='__main__':
    ints = sys.stdin.readline().rstrip().split(' ')
    A,B,n,x = int(ints[0]),int(ints[1]),long(ints[2]),int(ints[3])
    print find_value(A,B,n,x)

import sys
a,b,n,x = map(int,raw_input().split())
mod = 1000000007
if(a is 1):
	print (n*b + x)%mod
else :
	print (pow(a,n,mod)*x + b*(((pow(a,n,mod) - 1)*pow(a - 1,mod - 2,mod)) % mod))%mod

import sys

A, B, n, x = map(int, input().split())
mod = 10**9 + 7

def matmul(matA, matB):
    x, y, z = len(matA), len(matB[0]), len(matA[0])
    res = [[0]*y for _ in range(x)]

    for i in range(x):
        for j in range(y):
            for k in range(z):
                res[i][j] += matA[i][k] * matB[k][j]
            res[i][j] %= mod

    return res

matA = [
    [(A*x + B) % mod, 1],
    [x, 1]
]
matB = [
    [A, 0],
    [B, 1]
]
n -= 1

while n:
    if n & 1:
        matA = matmul(matA, matB)
    matB = matmul(matB, matB)
    n >>= 1

print(matA[0][0] % mod)

def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

mod = 10 ** 9 + 7
a, b, n, x = map(int, input().split())
ans = (pow(a, n, mod) * x % mod) % mod
if a != 1:
    ans2 = ((b * (pow(a, n, mod) - 1) % mod) * modinv(a - 1, mod)) % mod
else:
    ans2 = (b*(n*a)%mod)%mod
print((ans + ans2) % mod)

def calcInverse(r2, r1):
    global Mod
    s1, s2, t1, t2 = 1, 0, 0, 1

    while r2 != 0:
        q = r1 / r2
        r = r1 % r2
        s = s1 - q * s2
        t = t1 - q * t2

        r1, r2 = r2, r
        s1, s2 = s2, s
        t1, t2 = t2, t
    return t1 % Mod

def calcExponent(a, n):
    global Mod

    n = bin(n)[2:]
    Len = len(n) - 1
    tmp = a

    Sum = 1
    while Len >= 0:
        if n[Len] == '1': Sum = (Sum * tmp) % Mod
        tmp = (tmp * tmp) % Mod
        Len -= 1
    return Sum % Mod

## Entry of Program
#
#

Mod = 10 ** 9 + 7
a, b, n, x = [int(x) for x in raw_input().split(' ')]

if a == 1: print (n * b + x) % Mod
else: print ((b * (calcExponent(a, n) - 1) * calcInverse(a - 1, Mod)) % Mod + calcExponent(a, n) * x) % Mod

mod = 1000000007
def power(x, n):

   if(n==0):
      return 1

   tmp = power(x,n/2)

   if(n%2):
     return (((tmp*tmp)%mod)*x)%mod

   return (tmp*tmp)%mod

def divide(a , b):
    return (a * power(b,1000000005))%mod

ans=0;
a,b,n,x = raw_input().split(" ")
a,b,n,x = int(a) , int(b) , int(n) , int(x)
if(a>1): ans = (ans + (b* divide(power(a,n) - 1 , a-1))%mod)%mod
else : ans = (ans + (n*b)%mod)%mod
ans = (ans + (power(a,n)*x)%mod)%mod
if(ans<0):
    ans += mod
print ans

import math
[A,B,n,x]=[int(x) for x in raw_input().split()]
q=pow(10,9)+7
total=pow(A,n,q)*x
total%=q
if A==1:
    total=x+n*B
    total%=q
    print total
else:
    m=pow(A,n,q)-1
    m*= pow(A-1,q-2,q)
    m*=B
    total+=m
    total%=q
    print total

A, B, n, x = map(int, input().split())
MOD = 10 ** 9 + 7

def SD(i):
    if i == 0:
        return 1
    elif i % 2 == 0:
        return (1 + A * SD(i - 1)) % MOD
    else:
        md = pow(A, i // 2 + 1, MOD)
        return ((md + 1) * SD(i // 2)) % MOD

res = pow(A, n, MOD) * x + SD(n - 1) * B
print(res % MOD)

a,b,n,x = map(int,raw_input().split())

M = 1000000007

def exp(a,b):
	if b==0:
		return 1
	if b%2==1:
		return (a*exp(a,b-1))%M
	else:
		p = exp(a,b/2)
		return (p*p)%M

if a==1:
	res = (x+b*n)%M
else:
	res = ((exp(a,n)*x)%M + (((b*(exp(a,n)-1))%M) * exp(a-1,M-2))%M)%M

print res

import sys

MAXN = 10 ** 9 + 7
f = sys.stdin
A, B, n, x = map(int, f.readline().strip().split(' '))
if A == 1:
    print((x + n * B) % MAXN)
else:
    ans = x
    while n > 0:
        if n % 2:
            ans = (A * ans + B) % MAXN;
        B = B * (A + 1) % MAXN;
        A = A * A % MAXN;
        n /= 2
    print(ans)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time

(A, B, n, x) = (int(i) for i in input().split())

start = time.time()

md  = 1000000007

if A!=1 :
    an  = pow(A, n, md*(A-1))
    bn  = B*(an-1)//(A-1)
    ans = (an*x+bn)%md
else:
    ans = (x+B*n)%md
print(ans)

finish = time.time()
#print(finish - start)

import sys
input = sys.stdin.readline

mod = 10**9 + 7

def invmod(x, mod):
    return pow(x, mod-2, mod)

a, b, n, x = map(int, input().split())
if a == 1:
    ans = (pow(a, n, mod) * x + b * n) % mod
else:
    ans = pow(a, n, mod) * x + b * (pow(a, n, mod) - 1 + mod) * invmod(a-1, mod)
    ans %= mod
print(ans)

def mod_exp(x, y, p):
    res = 1
    x %= p
    while y:
        if y&1:
            res = (res * x) % p
        y >>= 1
        x = (x * x) % p
    return res

def power(a, b, m):
    x, y = 1, a
    while b:
        if b&1:
            x = (x * y) % m
        y = (y * y) % m
        b //= 2
    return x

def mod_inverse(a, m):
    return power(a, m - 2, m)

def solve(a, b, n, x):
    m = 10**9 + 7
    if a == 1:
        return (b * n * a + x) % m
    p = mod_exp(a, n, m)
    return (b * (p - 1) * mod_inverse(a - 1, m) + p * x) % m

a, b, n, x = map(int, input().split())

print(solve(a, b, n, x))

a,b,n,x=map(int,raw_input().split())
mod=10**9+7
if a==1:
  print (x+n*b)%mod
else:

  print (pow(a,n,mod)*x+b*(pow(a,n,mod)-1)*(pow(a-1,mod-2,mod))+mod)%mod

MOD = 10 ** 9 + 7

def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b / a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def gsum(a, r, n):
    inv = modinv(r - 1, MOD)
    return (a - a * pow(r, n + 1, MOD)) * inv * -1

a, b, n, x = map(int, raw_input().split())

if a == 1:
    print (b * n + x) % MOD
else:
    print (pow(a, n, MOD) * x + gsum(b, a, n - 1)) % MOD

a,b,n,x=map(int,input().split())
m=10**9+7
if a != 1:
    print( (pow(a,n,m)*x + b*(pow(a,n,m)-1) * pow(a-1,m-2,m))%m )
else:
    print((b*n+x)%m)

mod=1000000007
a,b,n,x=map(int, raw_input().split())
ans=(pow(a,n,mod)*x)%mod
if a>1:

    ans1=((pow(a,n,mod*(a-1))-1)%mod/(a-1))%mod
    ans1=(ans1*b)%mod
else:
    ans1=(n*b)%mod
ans=(ans+ans1)%mod
print ans

from decimal import *
M = int(1e9 + 7)
A, B, n, x = (int(x) for x in input().split())
if A > 1:
    An = pow(A, n, M)
    print((Decimal(An) * Decimal(x) + Decimal(B) * (Decimal(1-An)/Decimal(1-A))) % M)
else:
    print((x + B*n) % M)

a,b,n,x=map(int,input().split())
#print(int(x*(a**n)+b*(a**n-1)/(a-1)))
mod=10**9+7

def bin_pow(a,n):
    if n==1:
        return a
    else:
        if n%2==0:
            return (bin_pow(a,n//2)*bin_pow(a,n//2))%mod
        else:
            return (bin_pow(a,n//2)*bin_pow(a,n//2)*a)%mod

ans=x*bin_pow(a,n)
if a==1:
    ans+=b*n
else:
    ans+=b*(bin_pow(a,n)-1)/(a-1)
print(int(ans)%mod)

A, B, n, x = map(int, input().split())

def fast_exp(A, n, m):
    if n == 0:
        return 1
    if n & 1:
        return A * fast_exp(A, n - 1, m) % m
    return fast_exp(A * A % m, n // 2, m)

m = 10**9 + 7

ans = B * (fast_exp(A, n, m) - 1) * fast_exp(A - 1, m - 2, m) % m + fast_exp(A, n, m) * x % m
ans %= m

print(ans)

from sys import stdin

mod = 10**9+7

def geo(x, n, m):
    return (pow(x, n+1, m) - 1)*pow(x-1, m-2, m)

p, q, n, a = [int(x) for x in stdin.readline().rstrip().split()]
if p <= 1:
    print(a + q * n)
else:
    ans = (a * pow(p, n, mod) + q * (geo(p, n-1, mod) % mod)) % mod
    print(ans)

import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def inv(a):
    return pow(a, MOD-2, MOD)

a,b,n,x = Ri()
ans = pow(a, n, MOD) * x
if a > 1:
    ans += b * ( pow(a, n, MOD) -1 ) * inv(a-1)
if a == 1:
    ans+=1

print(ans%MOD)

mod = 10**9+7
def modExpo(a,n,x):
	if n==0:
		return 1
	elif n&1:
		return (a*modExpo((a*a)%x,(n-1)/2,x))%x
	else:
		return modExpo((a*a)%x,n/2,x)
a,b,n,x = map(int,raw_input().split())
an = modExpo(a,n,mod)
ans = (an*(x%mod))%mod
bmod = b%mod
for i in range(1,n):
	ans += ((an*bmod)/a)%mod
ans += bmod
ans %= mod
print ans

mod = int(10**9 + 7)
mud = int(10**9 + 6)

def powM(bs, pw, MOD):
    res = 1
    for i in range(pw.bit_length() - 1, -1, -1):
        res = (res * res) % MOD
        if (pw & (1 << i) > 0):
            res = (res * bs) % MOD

    return res

A, B, n, x = raw_input().split()

A = int(A)
B = int(B)
n = int(n) % mud
x = int(x)

An = powM(A, n, mod)
if (n > 1):
    fx = B * (mod + An - 1) % mod * powM(A - 1, mod - 2, mod)
else:
    fx = B

print (An * x + fx) % mod

M = int(1e9 + 7)
A, B, n, x = (int(x) for x in input().split())
if A != 1:
    An = pow(A, n, M)
    print(int(An * x + B * ((1-An)/(1-A))) % M)
else:
    print((x + B*n) % M)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 16:49:52 2020

@author: shailesh
"""
#def power_sum(A,n):
#    if A == 1:
#        return 1

A,B,n,x = [int(i) for i in input().split()]

#n-=1

m = 10**9 + 7
#val = A**n*x + B*(A**n - 1)//(A-1)

val = pow(A,n,m)*x + B*(pow(A,n,m) - 1)*pow(A-1,m-2,m)

print(val%(m))

import sys
input = sys.stdin.readline

a,b,n,x = (int(i) for i in input().split())
m = int(1e9) + 7
ans = (pow(a,n,m) * x) % m
n += 1
if a > 1:
    ans += ((( (1/(1-a)) - (pow(a,n-1,m)/(1-a)) ) % m) * b) % m
elif a==0:
    ans += b
elif a==1:
    ans += (n-1)*b % m
print(ans % m)

import math
import sys
sys.setrecursionlimit(10000)
def gcd(a, b):
    return b if a % b == 0 else gcd(b, a % b)

def lcm(a, b):
    return a*b/gcd(a,b)

def e_gcd(a, b):
    if (a == 0):
        return 0, 1, b
    x1, y1, d = e_gcd(b % a, a)
    x = y1 - (b / a) * x1
    y = x1
    return x, y, d

s = raw_input()
a, b, n, x = s.split()
a = int(a)
b = int(b)
n = int(n)
x = int(x)
base = int(1e9 + 7)
res = (pow(a, n, base) * x) % base
s = (b * (1 - pow(a, n, base)) % base + base) % base
q = (1- a) % base + base
q %= base
xx, yy, dd = e_gcd(q, base)
xx = (xx % base + base) % base
ans = res + s * xx
print ans % base

def extendedEuclidean(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = extendedEuclidean(b % a, a)
        return (g, x - (b // a) * y, y)

def exp_mod (base, exp, mod):
    if (mod == 1):
        return 0;

    number = 1;

    while (exp):
        if (exp & 1):
            number = (number * base) % mod;
        exp >>= 1
        base = (base * base) % mod;

    return number

if __name__ == '__main__':
    a, b, n, x = map(int, raw_input().split())

    m = 1000000007
    s = 0

    an = exp_mod (a, n, m)
    if a == 1:
        s = (n+m)%m
    else:
        p = (an-1)%m
        q = extendedEuclidean(a-1, m)[1]
        q = (q+m)%m
        s = (p%m)*(q%m)
        s = (s+m)%m
        # print s, a, an

    ss = ((an*x)+m)%m + ((b*s)+m)%m

    print ss

a, b, x, n = map(int, input().split())
mod = int(1e9) + 7

def comb(f, g): # f(g(n))
    return (f[0] * g[0] % mod, (f[0] * g[1] + f[1]) % mod)

def exp(f, n):
    res = (1, 0)
    cp = f
    for i in range(0, 63):
        if (n >> i) & 1:
            res = comb(cp, res)
        cp = comb(cp, cp)
    return res

res = exp((a, b), n)
print((res[0] * x + res[1]) % mod)

A, B, n, x = map(int, input().split())
MOD = 10 ** 19 + 7

def SD(i):
    if i == 0:
        return 1
    elif i % 2 == 0:
        return (1 + A * SD(i - 1)) % MOD
    else:
        md = pow(A, i // 2 + 1, MOD)
        return ((md + 1) * SD(i // 2)) % MOD

res = pow(A, n, MOD) * x + SD(n - 1) * B
print(res % MOD)

def modPow(base, pow, mod):
    ret = 1
    while pow > 0:
        if (pow % 2) == 0:
            base = (base * base) % mod
            pow >>= 1
        else:
            ret = (ret * base) % mod
            pow = pow - 1
    return ret;

a, b, x, n = map(int, raw_input().split())
modulo = 1000000007

first = modPow(a,n,modulo)
second = x % modulo
third = 0
if a != 1:
    third = modPow(a, n, modulo * (a - 1))
    third = modulo * (a - 1) - 1 if third == 0 else third - 1
    third = third / (a - 1)
else:
    third = (b * n) % modulo
ans = (((first * second) % modulo) + (third * b) % modulo) % modulo
print(ans)

mod = 10**9 + 7

def pow(num, p):
    global mod
    if p == 1:
        return num % mod
    ans = pow(num, p//2) % mod
    if p % 2 == 0:
        return ans * ans % mod
    else:
        return ans * ans * num % mod

A, B, n, x = tuple(map(int, input().split()))

if A != 1:
    ans = B
    ans *= (pow(A, n) - 1) * (A-1)**-1 % mod
    ans += pow(A, n) * x % mod
    ans %= mod
else:
    ans = x + n * B
    ans %= mod

print(round(ans))

a,b,n,x= map(int,input().split())
e = 10**9 + 7
if a==1:
    ans = (x + b*n)%e
else :
    ans = (pow(a,n,e)*x + (b*(pow(a,n,e) -1))//(a - 1))%e
print(int(ans))

'''
Name : Jaymeet Mehta
codeforces id :mj_13
Problem : Iterated linear function
'''
from sys import stdin,stdout
mod=10**9+7
A,B,n,x = map(int,stdin.readline().split())
if n==1:
    print(A*x+B)
else:
    ans=((pow(A,n,mod)*x)%mod+(B*((pow(A,n,mod)-1)*pow(A-1,mod-2,mod)))%mod)%mod
    print(ans)

data1 = raw_input().split(' ')

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		g, y, x = egcd(b % a, a)
		return (g, x - (b // a) * y, y)

def modinv(a, m):
	g, x, y = egcd(a, m)
	return x % m

data = []
for i in data1:
	data.append(int(i))
A = data[0]
B = data[1]
n = data[2]
x = data[3]
mod = 1000000007
sh1 = (pow(A,n,mod) * x) % mod
sh3 = B * ((pow(A, n, mod) - 1) * modinv(A - 1, mod)) % mod
print (sh1 + sh3) % mod

#A^n * x + B * ((A^(n-1) - 1)/(A - 1)) mod 10^9 + 7

a,b,n,x = map(int,input().split())
md = 10**9+7
mult  = lambda u,v : 0 if v==0 else (u+mult(u,v-1))%md if v % 2 == 1 else (2*mult(u,v//2))%md
res = mult(pow(a,n,md),x)+mult(mult(pow(a,n,md)-1+md,pow(a-1+md,md-2,md)),b)
res%=md
print(res if n!=1 else (mult(a,x)+b)%md)

a,b,n,x=map(int,raw_input().split())
mod=1000*1000*1000 +7
sum=0
if(a==1):
    sum=(x%mod+n*b%mod)%mod
else:
    sum=pow(a,n,mod)*x+(((b*(pow(a,n,mod)-1))%mod)*pow(a-1,mod-2,mod))%mod

print(sum)

def exp_mod (base, exp, mod):
    if (mod == 1):
        return 0;

    number = 1;

    while (exp):
        if (exp & 1):
            number = (number * base) % mod;
        exp >>= 1
        base = (base * base) % mod;

    return number

if __name__ == '__main__':
    a, b, n, x = map(int, raw_input().split())

    m = 1000000007
    s = 0

    an = exp_mod (a, n, m)
    if a == 1:
        s = n
    else:
        s = (a%m)*((an-1)%m)/((a-1)%m)
        s = (((1+s-an)%m)+m)%m

    ss = ((an*x)%m + m)%m
    ss = ((ss + b*s)%m + m)%m

    print ss

a,b,n,x = map(int,raw_input().split())

M = 1000000007

def exp(a,b):
	if b==0:
		return 1
	if b%2==1:
		return (a*exp(a,b-1))%M
	else:
		p = exp(a,b/2)
		return (p*p)%M

res = ((exp(a,n)*x)%M + (((b*(exp(a,n)-1))%M) * exp(a-1,M-2))%M)%M

print res

import sys

A, B, n, x = map(int, input().split())
mod = 10**9 + 7

def matmul(matA, matB):
    x, y, z = len(matA), len(matB[0]), len(matA[0])
    res = [[0]*y for _ in range(x)]

    for i in range(x):
        for j in range(y):
            for k in range(z):
                res[i][j] += matA[i][k] * matB[k][j]
            res[i][j] %= mod

    return res

matA = [
    [A*x + B, 1],
    [x, 1]
]
matB = [
    [A, 0],
    [B, 1]
]
n -= 1

while n:
    if n & 1:
        matA = matmul(matA, matB)
    matB = matmul(matB, matB)
    n >>= 1

print(matA[0][0])

global mod
mod=10**9+7
def power(x, y, p) :
    res = 1     # Initialize result

    # Update x if it is more
    # than or equal to p
    x = x % p

    while (y > 0) :

        # If y is odd, multiply
        # x with result
        if ((y & 1) == 1) :
            res = (res * x) % p

        # y must be even now
        y = y >> 1      # y = y/2
        x = (x * x) % p

    return res
def sol(a,b,x,n):
    if a==1:
        return (x+b*n)%mod
    an=power(a,n,mod)

    r=((1-an))

    f=(b*r)%mod+((x*(an))*(1-a))%mod
    f=f/(1-a)
    f=f%mod

    return int(f%mod)
a,b,n,x=list(map(int,input().split()))
print(sol(a,b,x,n))
""""
10000 10000 1000000000000000 10000
"""

a,b,n,x=map(int,raw_input().split())
mod=1000000007
ans=pow(a,n,mod)
ans=ans*x
ans%=mod
ans1=pow(a,n,mod)-1+mod
ans1%=mod
ans2=pow(a-1,mod-2,mod)
ans1=ans1*ans2
ans1%=mod
ans1*=b
ans1%=mod
ans=ans+ans1
ans%=mod
print ans

a,b,n,x=map(int,raw_input().split())
mod=10**9+7
print (pow(a,n,mod)*x+b*(pow(a,n,mod)-1)*(pow(a-1,mod-2,mod))+mod)%mod

A, B, n, x = (int(x) for x in input().split())
M = int(1e9 + 7)

def pow_mod(x, y, z):
    v = 1
    while y:
        if y & 1:
            v = (v * x) % z
        y >>= 1
        x = (x * x) % z
    return v

if A > 1:
    An = pow_mod(A, n, M)
    print((An * x + B * ((1-An)//(1-A))) % M)
else:
    print((x + B*n) % M)

from sys import stdin, stderr, stdout, exit
from math import gcd

readl = lambda : list(map(int, stdin.readline().strip().split()))

def nok(a, b):
    return a // gcd(a, b) * b

def main():
    A, B, n, x = readl()
    if(A == 1):
        stdout.write(str(B*n + x))
    else:
        stdout.write(str((A**n * ((A-1) * x + B) - B) // ((A-1) * x)))

if __name__ == '__main__':
    main()

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time

(A, B, n, x) = (int(i) for i in input().split())

start = time.time()

md  = 1000000007

if A!=1 :
    an  = pow(A, n, md*(A-1))
    bn  = B*(an-1)//(A-1)
    ans = (an*x+bn)%md
else:
    ans = (x+B*(n-1))%md
print(ans)

finish = time.time()
#print(finish - start)

a,b,n,x = map(int,input().split())
md = 10**9+7
mult  = lambda u,v : 0 if v==0 else (u+mult(u,v-1))%md if v % 2 == 1 else (2*mult(u,v//2))%md
get_prog = lambda a,b,n : mult(pow(a,n,md)-1+md,pow(a-1+md,md-2,md)) if a!=1 else 1
res = mult(pow(a,n,md),x)+mult(get_prog(a,b,n),b)
res%=md
print(res)

from sys import stdin

# 2**0 + 2**1 + 2**2 +..
def sum_pow(r, n, m=None):
    return div(add(1, -pow(r, n + 1)), (1 - r))

rints = lambda: [int(x) for x in stdin.readline().split()]
add = lambda a, b: (a % mod + b % mod) % mod
mult = lambda a, b: ((a % mod) * (b % mod)) % mod
div = lambda a, b: mult(a, inv(b))
inv = lambda a: pow(a, mod - 2, mod)
mod = 10 ** 9 + 7

a, b, n, x = rints()
g = [x]
for i in range(2):
    g.append(a * g[-1] + b)

fac = g[1] - g[0]
po = (g[-1] - g[1]) // fac

print(add(x, mult(fac, sum_pow(po, n - 1))))

import sys
input = sys.stdin.readline

a,b,n,x = (int(i) for i in input().split())
m = int(1e9) + 7
ans = (pow(a,n,m) * x) % m
n += 1
try:
    ans += ((( (1/(1-a)) - (pow(a,n-1,m)/(1-a)) ) % m) * b) % m
except:
    pass
print(ans % m)

e=10**9+7
a,b,n,x=map(int,input().split())
t=pow(a,n,e)
print((t*x+b*(t-1)//(a-1))%e if a-1else a*x+b)

a, b, n, x = map(int, input().split())
mod = 10 ** 9 + 7
res = pow(a, n, mod) * x
if a != 1:
    res += b * (pow(a, n, mod) - 1) // (a - 1)
else:
    res += b * n
res %= mod
print(res)

a,b,n,x = map(int,input().split())
md = 10**9+7
mult  = lambda u,v : 0 if v==0 else (u+mult(u,v-1))%md if v % 2 == 1 else (2*mult(u,v//2))%md
res = mult(pow(a,n,md),x)+mult(mult(pow(a,n,md)-1,pow(a-1,md-2,md)),b)
res%=md
print(res if n!=1 else (mult(a,x)+b)%md)

a,b,n,x= map(int,input().split())
e = 10**9 + 7
if a==1:
    ans = (x + b*n)%e
else :
    ans = (pow(a,n,e)*x + (b*pow(a,n,e)*pow(a-1,e-2,e))%e)%e
print(int(ans))

A,B,n,x=map(int,input().split())
def f(x):
    return A*x+B
bi=f(f(x))
ans=10**9+7
def fn(x,n):
    global bi
    if n==1:
        return f(x)
    elif n==2:
        return bi
    else:
        return fn(fn(x,n-n//2),n//2)

print(fn(x,n)%ans)

'''
Name : Jaymeet Mehta
codeforces id :mj_13
Problem : Iterated linear function
'''
from sys import stdin,stdout
mod=10**9+7
A,B,n,x = map(int,stdin.readline().split())
if n==1:
    print((A*x+B)%mod)
else:
    ans=((pow(A,n,mod)*x)%mod+(B*((pow(A,n,mod)-1)*pow(A-1,mod-2,mod)))%mod)%mod
    print(ans%mod)

a,b,n,x= map(int,input().split())
e = 10**9 + 7
if a==1:
    ans = (x + b*n)%e
else :
    ans = (pow(a,n,e)*x + (b*(pow(a,n,e) -1))//(a - 1))%e
print(int(ans))

global mod
mod=10**7
def power(x, y, p) :
    res = 1     # Initialize result

    # Update x if it is more
    # than or equal to p
    x = x % p

    while (y > 0) :

        # If y is odd, multiply
        # x with result
        if ((y & 1) == 1) :
            res = (res * x) % p

        # y must be even now
        y = y >> 1      # y = y/2
        x = (x * x) % p

    return res
def sol(a,b,x,n):
    if a==1:
        return (x+b*n)%mod
    an=power(a,n,mod)
    return int(((b%mod*((1-an)/(1-a))%mod)%mod+(x%mod*(an))%mod)%mod)
a,b,n,x=list(map(int,input().split()))
print(sol(a,b,x,n))
""""
10000 10000 1000000000000000 10000
"""

a, b, n, x = map(int, input().split())
mod = 10 ** 9 + 7
res = pow(a, n, mod) * x
if a != 1:
    res += ((pow(a, n) - 1) % mod) // (a - 1) * b % mod
else:
    res += b * n
res %= mod
print(res)

mod = 10**9 + 7

def pow(num, p):
    global mod
    if p == 1:
        return num % mod
    ans = pow(num, p//2) % mod
    if p % 2 == 0:
        return ans * ans % mod
    else:
        return ans * ans * num % mod

A, B, n, x = tuple(map(int, input().split()))

ans = B
if A != 1:
    ans *= (pow(A, n) - 1) % mod * (A-1)**-1 % mod
    ans %= mod
    ans += pow(A, n) * x % mod
ans %= mod

print(int(ans))

def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def modexp ( g, u, p ):
   """computes s = (g ^ u) mod p
      args are base, exponent, modulus
      (see Bruce Schneier's book, _Applied Cryptography_ p. 244)"""
   s = 1
   while u != 0:
      if u & 1:
         s = (s * g)%p
      u >>= 1
      g = (g * g)%p;
   return s

A,B,n,x=map(int, raw_input().split())
magic=10**9+7
if A==1:
    print (x+B)%magic
else:
    An=modexp(A, n, magic)
    Annumerator=(An-1)%magic
    Adenominator=(A-1)%magic
    Adenominator=modinv(Adenominator, magic)
    print ((An*x) % magic+ (((Annumerator*Adenominator)%magic) *B )%magic)%magic

a,b,n,x = map(int,input().split())
mod = 10**9 +7
ans = pow(a,n,mod)*x
gp = (pow(a,n,mod)-1)*(pow(a-1,mod-2,mod))*b
print((ans+gp)%mod)

A, B, n, x = map(int, input().split())

def fast_exp(A, n, m):
    if n == 0:
        return 1
    if n & 1:
        return A * fast_exp(A, n - 1, m) % m
    return fast_exp(A * A % m, n // 2, m)

m = 10**9 + 7

ans = B * (fast_exp(A, n, m) - 1) * fast_exp(A - 1, m - 2, m) % m + fast_exp(A, n, m) * x % m
ans %= m

print(ans)

import math
[A,B,n,x]=[int(x) for x in raw_input().split()]
q=pow(10,9)+7
total=pow(A,n,q)*x
total%=q
if A==1:
    total=A+n*B
    total%=q
    print total
else:
    m=pow(A,n,q)-1
    m*= pow(A-1,q-2,q)
    m*=B
    total+=m
    total%=q
    print total

a, b, x, n = map(int, input().split())
mod = int(1e9) + 7

def comb(f, g): # f(g(n))
    return (f[0] * g[0] % mod, (f[0] * g[1] + f[1]) % mod)

def exp(f, n):
    res = (1, 0)
    cp = f
    for i in range(0, 63):
        if (n >> i) & 1:
            res = comb(cp, res)
        cp = comb(cp, cp)
    return res

f = exp((a, b), n)
print((f[0] * x + f[1]) % mod)

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) % m
        return res ** 2 % m
    else:
        res = super_power(A, (n - 1)/2, m) % m
        return ((res ** 2) % m * A) % m

def geom_sum(power, p, q, b1):
    if q == 1:
        return power * b1
    return b1 * (1-p) / (1 - q)

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

a,b,n,x = map(int,raw_input().split())

M = 1000000007

def exp(a,b):
	if b==0:
		return 1
	if b%2==1:
		return (a*exp(a,b-1))%M
	else:
		p = exp(a,b/2)
		return (p*p)%M

if n==1:
	res = (a*x+b)%M
else:
	res = ((exp(a,n)*x)%M + (((b*(exp(a,n)-1))%M) * exp(a-1,M-2))%M)%M

print res

a,b,n,x=map(int,input().split())
#print(int(x*(a**n)+b*(a**n-1)/(a-1)))
mod=10**9+7

def bin_pow(a,n):
    if n==1:
        return a
    else:
        if n%2==0:
            return (bin_pow(a,n//2)*bin_pow(a,n//2))%mod
        else:
            return (bin_pow(a,n//2)*bin_pow(a,n//2)*a)%mod

ans=x*bin_pow(a,n)
if a==1:
    ans+=b*(n-1)
else:
    ans+=b*(bin_pow(a,n)-1)/(a-1)
print(int(ans)%mod)

import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def inv(a):
    return pow(a, MOD-2, MOD)

a,b,n,x = Ri()
ans = pow(a, n, MOD) * x
ans += b * ( pow(a, n, MOD) -1 ) * inv(a-1)

print(ans%MOD)

MOD = 10 ** 9 + 7

def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b / a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def gsum(a, r, n):
    inv = modinv(r - 1, MOD)
    return (a - a * pow(r, n + 1, MOD)) * inv * -1

a, b, n, x = map(int, raw_input().split())

if a == 1:
    print (n * x + b) % MOD
else:
    print (pow(a, n, MOD) * x + gsum(b, a, n - 1)) % MOD

a,b,n,x=map(int,raw_input().split())
mod=1000*1000*1000 +7
sum=0
if(a==1):
    sum=(x%mod+n*b%mod)%mod
else:
    sum=pow(a,n,mod)*x+(((b*(pow(a,n,mod)-1))%mod)*pow(a-1,mod-2,mod))%mod

print(sum)

from decimal import *
M = 1000000007
A, B, n, x = (int(x) for x in input().split())
if A > 1:
    An = pow(A, n, M)
    print((An * x + B * (1-An) * pow(1-A, M-1, M)) % M)
else:
    print((x + B*n) % M)

A, B, n, x = map(int, raw_input().split())
print x * A**n + B * (A**n-1) / max(1, (A-1))

import sys

f = sys.stdin
A, B, n, x = map(int, f.readline().strip().split(' '))
if A == 1:
    print(x + n * B)
else:
    ans = A ** n * x + (A ** n - 1) / (A - 1) * B
    print(ans)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 16:49:52 2020

@author: shailesh
"""
#def power_sum(A,n):
#    if A == 1:
#        return 1

A,B,n,x = [int(i) for i in input().split()]

#n-=1

m = 10**9 + 7
#val = A**n*x + B*(A**n - 1)//(A-1)

val = pow(A,n,m)*x + B*(pow(A,n,m) - 1)*pow(A-1,m-2,m)

print(val%(m))

a,b,n,x=map(int, input().split());
m=1000000007;
def modex(a,n):
	ans=1
	while n:
		if n&1:
			ans=(ans%m*a%m)%m
		a=(a%m*a%m)%m
		n>>=1
	return ans
if a==1:
	print((x%m+(b%m*(n-1)%m)%m)%m)
else:
	print(((modex(a,n)%m*x%m)%m+(b%m*((modex(a,n)%m-1%m)%m)%m*(modex(a-1,m-2)))%m)%m)

a, b, x, n = map(int, input().split())
mod = int(1e9) + 7

def comb(f, g): # f(g(n))
    return (f[0] * g[0] % mod, (f[0] * g[1] + f[1]) % mod)

def exp(f, n):
    res = (1, 0)
    cp = f
    for i in range(0, 63):
        if (n >> i) & 1:
            res = comb(cp, res)
        cp = comb(cp, cp)
    return res

res = exp((a, b), n)
print((res[0] * x + res[1]) % mod)