    #include <stdio.h>
	int mod=1000000007;
    long long int power(long long int base,long long int exponent)
    {
    	long long int res=1;
    	while(exponent)
    	{
    		if(exponent%2)
    			res=(res*base)%mod;
    		base=(base*base)%mod;
    		exponent=exponent/=2;
    	}
    	return res%mod;
    }

    long long int geometricsum(long long int r,long long int n)
    {
    	if(r==1)
    		return n%mod;
    	return (1-power(r,n))*power(1-r,mod-2)%mod;
    }

    int main()
    {
    	long long int a,b,n,x;
    	scanf("%lld %lld %lld %lld", &a,&b,&n,&x);
    	long long int answer=(power(a,n)*x+b*geometricsum(a,n))%mod;
    	printf("%lld", answer);
    	return 0;

    }

#include <stdio.h>

#define nMod 1000000007

long long power(long long a, long long x)
{
    long long s;
    if (x == 1) return a;
    if (x == 0) return 1;
    s = power(a, x/2);
    s = (s * s) % nMod;
    if (x % 2 == 1)
        s = (s * a) % nMod;
    return s % nMod;
}

int main()
{
    long long a, b, n, x, s = 0,k;
    scanf("%I64d %I64d %I64d %I64d", &a, &b, &n, &x);
    s = (power(a,n)*x) % nMod;
    s = (s + b) % nMod;
    if (a == 1)
        s += (b*((n-1) % nMod));
    else
    s = (s + (b*((((power(a,n)-a) + nMod) %nMod)*(power(a-1,nMod-2))% nMod))% nMod) % nMod;
    k = power(a-1,nMod-2);
    printf("%I64d", (s + nMod) % nMod);
    return 0;
}

#include <stdio.h>

#define M	1000000007

struct matrix {
	int a, b, c, d;
} m;

int mult(int a, int b, int c, int d) {
	return ((long long) a * b % M + (long long) c * d % M) % M;
}

struct matrix power(struct matrix m, long long n) {
	struct matrix m_;
	int a, b, c, d;

	if (n == 0) {
		m_.a = 1;
		m_.b = 0;
		m_.c = 0;
		m_.d = 1;
	} else {
		m_ = power(m, n / 2);
		a = m_.a;
		b = m_.b;
		c = m_.c;
		d = m_.d;
		m_.a = mult(a, a, c, b);
		m_.b = mult(b, a, d, b);
		m_.c = mult(a, c, c, d);
		m_.d = mult(b, c, d, d);
		if (n % 2 != 0) {
			a = m_.a;
			b = m_.b;
			c = m_.c;
			d = m_.d;
			m_.a = mult(a, m.a, c, m.b);
			m_.b = mult(b, m.a, d, m.b);
			m_.c = mult(a, m.c, c, m.d);
			m_.d = mult(b, m.c, d, m.d);
		}
	}
	return m_;
}

int main() {
	int a, b, x;
	long long n;

	scanf("%d%d%lld%d", &a, &b, &n, &x);
	m.a = a;
	m.b = b;
	m.c = 0;
	m.d = 1;
	m = power(m, n);
	printf("%lld\n", (((long long) x * m.a % M) + m.b) % M);
	return 0;
}

#include <stdio.h>
typedef long long ll;
ll MOD = 1000000007 ;
ll MOD2 = 1000000006 ;

ll gcdExtended(ll a, ll b, ll *x, ll *y);

ll power(ll x, ll y, ll p) ;

// Function to find modulo inverse of a
ll modInverse(ll a, ll m)
{
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);

        // m is added to handle negative x
        ll res = (x%m + m) % m;
        return res ;

}

// C function for extended Euclidean Algorithm
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

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

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll main(ll argc, char const *argv[])
{
    ll A,B,n,x;
    scanf("%lld %lld %lld %lld",&A,&B,&n,&x);
    ll answer = 0;
    ll apart = 1;
    ll itna = n%(MOD2);
    if(itna==0)
    {
        printf("%lld\n",x%MOD);
    }
    else
    {
    ll second = 1;
    if(A!=1)
    {
    ll dot = power(A,itna,MOD);
    answer = (answer +((dot*x) % MOD))%MOD ;
    ll ert  = dot-1 ;
    ll gh = A-1 ;
    answer = (answer+(((modInverse(A-1,MOD)*ert)%MOD)*B)%MOD)%MOD;
    }
    else if(A==1)
    {
        answer =  (answer + x)%MOD ;
    //    printf("yele %lld\n\n",itna);
        answer = (answer + ((B%MOD)*(n%MOD)%MOD))%MOD ;
    }
    //prllf("%lld\n",);
    printf("%lld\n",answer);
    }
    return 0;
}

#include <stdio.h>

#define M	1000000007

struct matrix {
	int a, b, c, d;
} m;

struct matrix power(struct matrix m, long long n) {
	struct matrix m_;
	int a, b, c, d;

	if (n == 0) {
		m_.a = 1;
		m_.b = 0;
		m_.c = 0;
		m_.d = 1;
	} else {
		m_ = power(m, n / 2);
		a = m_.a;
		b = m_.b;
		c = m_.c;
		d = m_.d;
		m_.a = ((long long) a * a % M + (long long) c * b % M) % M;
		m_.b = ((long long) b * a % M + (long long) d * b % M) % M;
		m_.c = ((long long) a * c % M + (long long) c * d % M) % M;
		m_.d = ((long long) b * c % M + (long long) d * d % M) % M;
		if (n % 2 != 0) {
			a = m_.a;
			b = m_.b;
			c = m_.c;
			d = m_.d;
			m_.a = ((long long) a * m.a % M + (long long) c * m.b % M) % M;
			m_.b = ((long long) b * m.a % M + (long long) d * m.b % M) % M;
			m_.c = ((long long) a * m.c % M + (long long) c * m.d % M) % M;
			m_.d = ((long long) b * m.c % M + (long long) d * m.d % M) % M;
		}
	}
	return m_;
}

int main() {
	int a, b, x;
	long long n;

	scanf("%d%d%lld%d", &a, &b, &n, &x);
	m.a = a;
	m.b = b;
	m.c = 0;
	m.d = 1;
	m = power(m, n);
	printf("%lld\n", (((long long) x * m.a % M) + m.b) % M);
	return 0;
}

/*
   Sachin Chandani
   IIIT Hyderabad
 */

#include<stdio.h>
#include<limits.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
# define M 1000000007
long long int fast_mul (long long int n,long long int x) ;
long long int m (long long int a) ;
long long int fast_mul (long long int n,long long int x) {
	long long int p ;
	if (x==0)
		return 1 ;
	else if (x==1)
		return n%M ;
	else
	{  p=fast_mul(n,x/2) ;
		p=(p*p)%M ;
		if (x%2==1)
			p=(p*n)%M ;
		return p ;
	}
}
long long int m (long long int a) {
	return fast_mul(a,M-2) ;
}
int main () {
	long long int a,b,n,x ,i,sum,aux,mmi ;
	scanf("%lld%lld%lld%lld",&a,&b,&n,&x) ;
	a=a%M ;
	x=x%M ;
	b=b%M ;
	aux=fast_mul(a,n) ;
	mmi=m(a-1) ;
	sum=(aux*x)%M ;
	if (a==1)
		n=n%M ;
	else
		n=((aux-1)*mmi)%M ;
	n=n%M ;
	n=(n*b)%M ;
	sum=(sum+n)%M ;
	printf("%lld\n",sum) ;
	return 0 ;
}

#include<stdio.h>
long long int a,b,n,x,y,z;
long long int mod = 1000000007;
long long int modpowfast(long long int base,long long int e)
{
	long long int ans=1;
	while(e>0)
	{
		if(e&1)
			ans=(ans*base)%mod;
		base=(base*base)%mod;
		e=e>>1;
	}
	return ans;
}

int main()
{
	long long int ans=0;
	scanf("%lld %lld %lld %lld",&a,&b,&n,&x);
	if(a==1)
	{
		n=n%mod;
		ans  =  (x + (n*b)%mod)%mod;
	}
	else
	{
		y = modpowfast(a,n);
		z = modpowfast(a-1,mod-2);
//		printf("%lld %lld\n",y,z);
		ans = ((y*x)%mod + (((y-1)*z)%mod)*b )%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

#include<stdio.h>

unsigned long long int m=1000000007;
unsigned long long int bigmod(unsigned long long int x, unsigned long long int n)
{
    if(n==0) return 1;

    if(n%2==0)
    {
    unsigned long long int num= bigmod(x,n/2);
    return ((num%m)*(num%m))%m;
    }

    else
        return ((x%m)*(bigmod(x,n-1)%m))%m;

}

int main()
{
    unsigned long long int  sum1=0,sum2=0,sum=0,n,A,B,x;

    scanf("%llu %llu %llu %llu",&A,&B,&n,&x);

    if(A==1) printf("%llu\n",((x%m)+((B%m)*(n%m))%m)%m);
    else{

    sum1=bigmod(A,n)%m;
    sum2=(sum1-1)%m;

    sum1=((sum1%m)*(x%m))%m;
    sum2=((sum2%m)*(B%m))%m;

    sum2=((sum2%m)* (bigmod(A-1,m-2))%m)%m;

    sum=((sum1%m)+(sum2%m))%m;

    printf("%llu\n",sum%m);

    }
    return 0;
}

#include<stdio.h>
#include<math.h>
long long int power(long long int x,long long int y)
{
	int hel=1;
	x= x%1000000007;
	while(y>0)
	{
		if((y&1)==1)
		{
			hel=(hel*x)%1000000007;
		}
		x= (x*x)%1000000007;
		y= y>>1;
	}
	return hel%1000000007;
}
long long int cal(long long int x,long long int y)
{
	if(x==1)
	{
		return y%1000000007;
	}
	else
	{
		return (1-power(x,y))*power(1-x,1000000005)%1000000007;
	}
}

int main()
{
	long long int a,b,n,x,sum;
	scanf("%lld%lld%lld%lld",&a,&b,&n,&x);
	sum=(power(a,n)*x+(b*cal(a,n)))%1000000007;
	printf("%lld\n",sum);
	return 0;
}

#include<stdio.h>
const int mod = 1e9+7;
typedef long long ll;
ll quick_pow(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b&1)
        {
            ans = (ans * a) % mod;
        }
        a = (a*a) % mod;
        b >>= 1;
    }
    return ans;
}
ll inv(int x,int p)
{
    return quick_pow(x,p-2);
}
int main()
{
    ll a, b, x;
    ll n,ans, s, A, B;
    scanf("%I64d%I64d%I64d%I64d",&a,&b,&n,&x);
    {
        if(a == 1)
        {
            ans = (x + (n%mod)*b) % mod;
        }
        else if(n == 1)
        {
            ans = (a*x+b*n%mod) % mod;
        }
        else
        {
            ans = (quick_pow(a,n) * x) % mod; //a^n * b
            s = (  (quick_pow(a,n) - 1) * b) % mod;
            A = inv(a-1,mod);
            ans = (ans+A*s)%mod;
        }
    }
    printf("%I64d\n",ans);
}

#include <stdio.h>
#include <stdlib.h>
long long pp=1e9+7;
long long VLL(long long a,long long b,long long p)
{
    long long ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%p;
        a=a*a%p;
        b>>=1;
    }
    return ans;
}
int main()
{
    long long a,b,c,d,x,m,n;
    scanf("%lld %lld %lld %lld",&a,&b,&n,&x);
    if(a!=1)
    {
        c=VLL(a,n,pp); d=VLL(a-1,pp-2,pp);
        d=(((c-1)%pp)*(d%pp))%pp;
    }
    else
        d=n,c=1;
    d=((d%pp)*(b%pp))%pp;
    c=(((c%pp)*(x%pp))%pp+d)%pp;
    printf("%lld\n",c);
    return 0;
}

long long int modular_pow(long long int base, long long int exponent, long long int modulus)
{
    long long int result = 1;
    while (exponent > 0)
    {
        if (exponent % 2 == 1)
            result = (result * base) % modulus;
        exponent = exponent >> 1;
        base = (base * base) % modulus;
    }
    return result;
}
int powercal(int x, unsigned int y)
{
    int res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = res*x;

        // n must be even now
        y = y>>1; // y = y/2
        x = x*x;  // Change x to x^2
    }
    return res;
}
int main ()
{
    long long int  n,a,b,x,ans,e12,ef,e,e1,e2,pr,en;
    long long int p=1000000007;
    scanf ("%I64d %I64d %I64d %I64d",&a,&b,&n,&x);
    //printf ("%I64d\n",(-1)%3);
    if (a!=1)
    {
        e1=b%p;
        pr=modular_pow(a,n,p);//(a^n)%p
        e2=(pr+(p-1))%p;
        //printf ("%I64d ",e2);// (a^n-1) %p
        en=modular_pow(a-1,p-2,p);
        e2=((e2%p)*en)%p;
        e12=(e1*e2)%p;
        e=((x%p)*pr)%p;
        ef=(e12+e)%p;
        printf ("%I64d",ef);
        return 0;
    }
    else
    {
        e=((n%p)*(b%p))%p;
        ef=(e+(x%p))%p;
      printf ("%I64d",ef);
      return 0;
    }
}

#include<stdio.h>

long long m=1000000007;

long long big(long long a,long long n)
{
    long long x=1;
    while(n)
    {
        if(n%2) x = (x*a)%m;
        a = (a*a)%m;
        n = n/2;
    }
    return x%m;
}

long long inv(long long a,long long n)
{
    long long p,q,r,s;
    if(a==1)    return (n%m);
    else
    {
        p = big(a,n)%m;
        q = p-1;
        r = big(a-1,m-2)%m;
        s = (q*r)%m;
        return s;
    }
}

int main()
{
    long long a,b,n,x,p,q,r;
    scanf("%lld %lld %lld %lld",&a,&b,&n,&x);
    p = (big(a,n)*(x%m))%m;
    q = (inv(a,n)*b)%m;
    r = (p+q)%m;
    printf("%lld\n",r);
    return 0;
}

#include<stdio.h>
#include<math.h>
long long n;
long long a,b,x;
long long que[100];
int q;
int main()
{
	scanf("%lld%lld%lld%lld",&a,&b,&n,&x);
	long long an=1;
	long long chuc=a-1;
	long long two=pow(2,62);
	long long mod=pow(10,9)+7;
	if(a==1){
		printf("%lld",(x+(b*(n%mod)%mod))%mod);
	}
	else{
		while(n>0){
			if(n>=two){
				n-=two;
				q++;
				que[q]=two;
			}
			two=two/2;
		}
		two=1;
		long long c=a;
		while(q>0){
			if(two==que[q]){
				an=(an*a)%mod;
				q--;
			}
			a=(a*a)%mod;
			two=two*2;
		}
		int chumod=mod-2;
		two=pow(2,50);
		while(chumod>0){
			if(chumod>=two){
				chumod-=two;
				q++;
				que[q]=two;
			}
			two=two/2;
		}
		two=1;
		long long chu=1;
		while(q>0){
			if(two==que[q]){
				chu=(chu*chuc)%mod;
				q--;
			}
			chuc=(chuc*chuc)%mod;
			two=two*2;
		}
		printf("%lld",((an*x)%mod+((((an-1)*chu)%mod)*b)%mod)%mod);
	}
	return 0;
 }

#include <stdio.h>
#define M 1000000007
long long int fast_mul (long long int n,long long int x) {
	long long int p ;
	if (x==0)
	  return 1 ;
	else if (x==1)
	  return n%M ;
	else
	{  p=fast_mul(n,x/2) ;
	   p=(p*p)%M ;
	   if (x%2==1)
	     p=(p*n)%M ;
	   return p ;
	}
}
long long int m (long long int a) {
	return fast_mul(a,M-2) ;
}
int main () {
	long long int a,b,n,x ,i,sum,aux,mmi ;
	scanf("%I64d%I64d%I64d%I64d",&a,&b,&n,&x) ;
	a=a%M ;
	x=x%M ;
	b=b%M ;
	aux=fast_mul(a,n) ;
	mmi=m(a-1) ;
	sum=(aux*x)%M ;
	if (a==1)
	 n=n%M ;
	else
	n=((aux-1)*mmi)%M ;
	n=n%M ;
	n=(n*b)%M ;
	sum=(sum+n)%M ;
	printf("%I64d\n",sum) ;
	return 0 ;
}

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define MOD 1000000007
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

long long expo(long long x, long long n){
    x %= MOD;
    long long res = 1;

    while (n){
        if (n & 1LL) res = (res * x) % MOD;
        x = (x * x) % MOD;
        n >>= 1LL;
    }

    return (res % MOD);
}

long long sumpow(long long x, long long n){
    if (n == 1) return (x % MOD);
    if (n & 1) return (sumpow(x, n - 1) + expo(x, n)) % MOD;
    else{
        long long r = sumpow(x, n >> 1);
        return (r + (r * expo(x, n >> 1))) % MOD;
    }
}

int main(){
    long long a, b, n, x, y, z, res;

    while (scanf("%lld %lld %lld %lld", &a, &b, &n, &x) != EOF){
        res = (expo(a, n) * x + b) % MOD;
        if (n > 1) res = (res + (b * sumpow(a, n - 1))) % MOD;
        printf("%lld\n", res % MOD);
    }
    return 0;
}

/*
 * 678D
 *
 * (A-1)y = (A-1)xA^n + BA^n - B
 */
#include <stdio.h>
#include <stdlib.h>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <limits.h>
#define offset(t,m) ((unsigned long)&(((t*)0)->m))
#define container_of(a,t,m) ((t*)((unsigned long)a-offset(t,m)))
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define SWP(a, b) if ((a) != (b)) do {(a) ^= (b); (b) ^= (a); (a) ^= (b);} while(0)
#define MAX(x,y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define IR(x, start, end) ((x) >= (start) && (x) < (end))
#define IRE(x, start, end) ((x) >= (start) && (x) <= (end))
#define ABS(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#endif
#ifndef _WCC_NUMTH_H
#define _WCC_NUMTH_H
#include <assert.h>
#define NUMTH_CORRECT(x, mod) ((x) += ((x) < 0 ? (mod) : 0))
#define NUMTH_ENS (-1)
long long numth_modexp(long long a, long long b, long long n);
long long numth_gcd(long long a, long long b);
void numth_gcd_e(long long a, long long b, long long *d, long long *x, long long *y);
int numth_mle(long long a, long long b, long long n, long long *x, long long *gcd);
#define numth_for_each_solution(i, x, n, d) \
	for ((i) = 0; (i) < (d); (i) += 1, (x) = ((x) + (n) / (d)) % (n))
int numth_divisors(long long k, long long divs[], long long *ndivs);
#endif
#define P LL(1000000007)
/* x, y, n must not be negitive */
#define modmul(x, y, n) ((((x) % (n)) * ((y) % (n))) % (n))
#define modpls(x, y, n) ((((x) % (n)) + ((y) % (n))) % (n))
int main(void)
{
	long long A, B, n, x;
	long long right, q, ans, d;
	scanf("%lld%lld%lld%lld", &A, &B, &n, &x);
	if (A == 1) {
		ans = modpls(x, modmul(B, n, P), P);
		goto print_answer;
	}
	q = numth_modexp(A, n, P);
	//printf("q: %lld\n", q);
	right = modmul(modmul(A - 1, x, P), q, P) + modmul(B, q, P) - B;
	//printf("right: %lld\n", right);
	NUMTH_CORRECT(right, P);
	numth_mle(A - 1, right, P, &ans, &d);
	assert(d == 1);
	print_answer:
	printf("%lld\n", ans);
	return 0;
}

static long long numth_do_gcd(long long a, long long b);
static void numth_do_gcd_e(long long grt, long long les, long long *d, long long *x, long long *y);

long long numth_modexp(long long a, long long b, long long n)
{
	static long long bit63 = (unsigned long long)0x8000000000000000;
	long long square = 1;
	int i;

	assert(b >= 0 && n > 0);

	//FIXME: '==' > '&'
	for(i = 63; i >= 0 && (b & bit63) == 0; --i)
		b <<= 1;
	for(; i >= 0; --i) {
		square = (square * square) % n;
		if (b & bit63)
			square = (square * a) % n;
		b <<= 1;
	}

	return square;
}

long long numth_gcd(long long a, long long b)
{
	if (a == 0 && b == 0)
		return 0;
	if (a < 0)
		a *= -1;
	if (b < 0)
		b *= -1;
	/* We DON'T need a > b */
	return numth_do_gcd(a, b);
}

/* 大数除小数, 小数除余数 */
static long long numth_do_gcd(long long a, long long b)
{
	long long r;

	if (!b)
		return a;

	for (r = a % b; r != 0; r = a % b) {
		a = b;
		b = r;
	}

	return b;
}

void numth_gcd_e(long long a, long long b, long long *d, long long *x, long long *y)
{
	if (a == 0 && b == 0) {
		*d = *x = *y = 0;
		return;
	}

	if (a < 0)
		a *= -1;
	if (b < 0)
		b *= -1;

	if (a < b)
		numth_do_gcd_e(b, a, d, y, x);
	else
		numth_do_gcd_e(a, b, d, x, y);
}

static void numth_do_gcd_e(long long a, long long b, long long *d, long long *x, long long *y)
{
	long long tmp;

	if (b == 0) {
		*d = a;
		*x = 1;
		*y = 0;
		return;
	}
	numth_do_gcd_e(b, a % b, d, x, y);
	tmp = *x;
	*x = *y;
	//TODO: overflow?
	*y = (tmp - (a / b) * (*y));
}

int numth_mle(long long a, long long b, long long n, long long *solution, long long *gcd)
{
	long long d, x, y;

	assert(n != 0);

	if (n < 0)
		n *= (-1);
	if (a < 0)
		a *= (-1);
	if (b < 0)
		b *= (-1);

	numth_gcd_e(a, n, &d, &x, &y);
	assert(d != 0); //d=0 if and only if a=b=0

	if (b % d)
		return NUMTH_ENS;

	*solution = ((b / d) * (x % n)) % n;
	NUMTH_CORRECT(*solution, n);
	*gcd = d;

	return 0;
}

int numth_divisors(long long k, long long divs[], long long *ndivs)
{
	long long i, n;

	assert(k > 0);

	n = 0;
	for (i = 1; i * i < k; ++i)
		if (k % i == 0)
			divs[n++] = i;

	if (i * i == k) {
		divs[n++] = i;
		i = n - 2;
	} else {
		i = n - 1;
	}

	for (; i >= 0; --i)
		divs[n++] = k / divs[i];

	*ndivs = n;

	return 0;
}

#include <stdio.h>
# define m 1000000007
long long int power(long long int x,long long int y)
{
	if(y==0)
	return 1;
	else if(y%2==0)
	{
		long long int z;
		z=power(x,y/2)%m;
		return (z*z)%m;
	}
	else
	{
		long long int z;
		z=power(x,y/2)%m;
		return ((x%m*z%m)%m*z)%m;
	}
}
int main()
{
	long long int n,a,b,x,i,ans=0;
	scanf("%lld %lld %lld %lld",&a,&b,&n,&x);
       if(a!=1)
{
//	for(i=0;i<n;i++)
//	{
		ans=(power(a,n)-1)%m;
		if(ans<0)
		ans=ans+m;
		ans=(ans%m*b%m)%m;
		if(ans<0)
		ans+=m;
		if(a-1>0)
		ans=((ans%m)*power(a-1,m-2)%m)%m;
		 ans=ans%m;
//	}
	ans=(ans+(power(a,n)%m*x%m)%m)%m;
	ans=ans%m;}
else
ans=((n%m*b%m)%m+x)%m;
	printf("%lld\n",ans);
	return 0;
}

#include<stdio.h>
#define MOD 1000000007

int main(){
	long long int n,a,b,x;
	scanf("%lld%lld%lld%lld",&a,&b,&n,&x);
	while(n>0){
		if(n%2){
			x=a*x+b;
			x%=MOD;
		}
		b=a*b+b;
		a=a*a;
		a%=MOD;
		b%=MOD;
		n/=2;
	}
	printf("%lld\n",x);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

//input definitions
#define sd(x) scanf("%d",&x);
#define slld(x) scanf("%lld",&x);
#define ss(x) scanf("%s",x);
#define sf(x) scanf("%f",&x);
#define slf(x) scanf("%lf",&x);

//output definitions
#define pd(x) printf("%d",x);
#define plld(x) printf("%lld",x);
#define ps(x) printf("%s",x);
#define pf(x) printf("%f",x);
#define plf(x) printf("%lf",x);
#define pnl printf("\n");
#define psp printf(" ");

//define datatypes
typedef long long int ll;

//loops
#define upto(x) for(;i<=x;i++)
#define fl(i,a,b,c) for(i=a;i<=b;i+=c)
#define wl(x) while(x--)

#define MOD 1000000007

ll power(ll a, ll b){
	ll ans = 1;
	while(b > 0){
		if(b & 1){
			ans = (ans * a) % MOD;
		}
		a = (a*a) % MOD;
		b/=2;
	}
	return ans%MOD;
}

int main(void) {
	ll a,b,c,d,n,x;
	slld(a) slld(b) slld(n) slld(x)
	if(a == 1){
		plld((x+((n%MOD)*b)%MOD)%MOD)
	}
	else if(n == 1){
		plld(((a*x)%MOD + b) % MOD)
	}
	else{
		ll ans = (power(a,n) * x) % MOD;
		ans = (ans + (((((power(a,n) - 1 + MOD) % MOD) * power(a-1,MOD-2)) % MOD) * b) % MOD ) % MOD;
		plld(ans)
	}
	return 0;

}

#include<stdio.h>
#include<string.h>
#include<math.h>
typedef unsigned long long LL;
LL m=1000000007;

LL bigmod(LL a,LL b, LL m)
{
    if(b==0)    return 1%m;
    LL x=bigmod(a,b/2,m);
    x=(x*x)%m;
    if(b%2==1)
        x=(x*a)%m;
    return x;
}
int main()
{
    LL n, a, b, x, f, ans, f2, f3;
    char  s[200010];
    scanf("%llu %llu %llu %llu",&a,&b,&n,&x);
    a=a%m;
    b=b%m;
    f = bigmod(a, n, m);
    f2 = (f * (x % m)) % m;
    if(a==1)
    {
        ans = (f2 + (b* (n%m) )% m) % m;
    }
    else
    {
        f3 = bigmod(a-1, m-2, m);
        //ans = (f2+(b*((f-1)*f3)%m)%m)%m;
        ans = (b * (f-1))%m;
        ans = (ans* f3)%m;
        ans = (ans+ f2) %m;
    }

    printf("%llu\n",ans);
    return 0;

}

#include <stdio.h>

#define nMod 1000000007

long long power(long long a, long long x)
{
    long long s;
    if (x == 1) return a;
    if (x == 0) return 1;
    s = power(a, x/2);
    s = (s * s) % nMod;
    if (x % 2 == 1)
        s = (s * a) % nMod;
    return s % nMod;
}

int main()
{
    long long a, b, n, x, s = 0,k;
    scanf("%I64d %I64d %I64d %I64d", &a, &b, &n, &x);
    s = (power(a,n)*x) % nMod;
    s = (s + b) % nMod;
//    k = (((power(a,n)-a) + nMod) % nMod) /(a-1);
    if (a == 1) s += n-1;
    else
    s = (s + (b*(((((power(a,n)-a) + nMod) %nMod)/(a-1))% nMod))% nMod) % nMod;
    printf("%I64d", (s + nMod) % nMod);
    return 0;
}

#include <stdio.h>

#define nMod 1000000007

long long power(long long a, long long x)
{
    long long s;
    if (x == 1) return a;
    if (x == 0) return 1;
    s = power(a, x/2);
    s = (s * s) % nMod;
    if (x % 2 == 1)
        s = (s * a) % nMod;
    return s % nMod;
}

int main()
{
    long long a, b, n, x, s = 0,k;
    scanf("%I64d %I64d %I64d %I64d", &a, &b, &n, &x);
    s = (power(a,n)*x) % nMod;
    s = (s + b) % nMod;
//    k = (((power(a,n)-a) + nMod) % nMod) /(a-1);
    if (a == 1) s += n;
    else
    s = (s + (b*(((((power(a,n)-a) + nMod) %nMod)/(a-1))% nMod))% nMod) % nMod;
    printf("%I64d", (s + nMod) % nMod);
    return 0;
}

#include <stdio.h>

#define nMod 1000000007

long long power(long long a, long long x)
{
    long long s;
    if (x == 1) return a;
    if (x == 0) return 1;
    s = power(a, x/2);
    s = (s * s) % nMod;
    if (x % 2 == 1)
        s = (s * a) % nMod;
    return s % nMod;
}

int main()
{
    long long a, b, n, x, s = 0,k;
    scanf("%I64d %I64d %I64d %I64d", &a, &b, &n, &x);
    s = (power(a,n)*x) % nMod;
    s = (s + b) % nMod;
//    k = (((power(a,n)-a) + nMod) % nMod) /(a-1);
    if (a == 1) s += n-1;
    else
    s = (s + (b*((((power(a,n)-a) + nMod) %nMod)*(power(a-1,nMod-2))% nMod))% nMod) % nMod;
    printf("%I64d", (s + nMod) % nMod);
    return 0;
}

#include <stdio.h>

#define M	1000000007

struct matrix {
	int a, b, c, d;
} m;

struct matrix power(struct matrix m, int n) {
	struct matrix m_;
	int a, b, c, d;

	if (n == 0) {
		m_.a = 1;
		m_.b = 0;
		m_.c = 0;
		m_.d = 1;
	} else {
		m_ = power(m, n / 2);
		a = m_.a;
		b = m_.b;
		c = m_.c;
		d = m_.d;
		m_.a = ((long long) a * a % M + (long long) c * b % M) % M;
		m_.b = ((long long) b * a % M + (long long) d * b % M) % M;
		m_.c = ((long long) a * c % M + (long long) c * d % M) % M;
		m_.d = ((long long) b * c % M + (long long) d * d % M) % M;
		if (n % 2 != 0) {
			a = m_.a;
			b = m_.b;
			c = m_.c;
			d = m_.d;
			m_.a = ((long long) a * m.a % M + (long long) c * m.b % M) % M;
			m_.b = ((long long) b * m.a % M + (long long) d * m.b % M) % M;
			m_.c = ((long long) a * m.c % M + (long long) c * m.d % M) % M;
			m_.d = ((long long) b * m.c % M + (long long) d * m.d % M) % M;
		}
	}
	return m_;
}

int main() {
	int a, b, n, x;

	scanf("%d%d%d%d", &a, &b, &n, &x);
	m.a = a;
	m.b = b;
	m.c = 0;
	m.d = 1;
	m = power(m, n);
	printf("%lld\n", ((long long) x * m.a + m.b) % M);
	return 0;
}

#include <stdio.h>

#define M	1000000007

struct matrix {
	int a, b, c, d;
} m;

struct matrix power(struct matrix m, int n) {
	struct matrix m_;
	int a, b, c, d;

	if (n == 0) {
		m_.a = 1;
		m_.b = 0;
		m_.c = 0;
		m_.d = 1;
	} else {
		m_ = power(m, n / 2);
		a = m_.a;
		b = m_.b;
		c = m_.c;
		d = m_.d;
		m_.a = ((long long) a * a % M + (long long) c * b % M) % M;
		m_.b = ((long long) b * a % M + (long long) d * b % M) % M;
		m_.c = ((long long) a * c % M + (long long) c * d % M) % M;
		m_.d = ((long long) b * c % M + (long long) d * d % M) % M;
		if (n % 2 != 0) {
			a = m_.a;
			b = m_.b;
			c = m_.c;
			d = m_.d;
			m_.a = ((long long) a * m.a % M + (long long) c * m.b % M) % M;
			m_.b = ((long long) b * m.a % M + (long long) d * m.b % M) % M;
			m_.c = ((long long) a * m.c % M + (long long) c * m.d % M) % M;
			m_.d = ((long long) b * m.c % M + (long long) d * m.d % M) % M;
		}
	}
	return m_;
}

int main() {
	int a, b, n, x;

	scanf("%d%d%d%d", &a, &b, &n, &x);
	m.a = a;
	m.b = b;
	m.c = 0;
	m.d = 1;
	m = power(m, n);
	printf("%lld\n", (long long) x * m.a + m.b);
	return 0;
}

#include <stdio.h>

#define M	1000000007

struct matrix {
	int a, b, c, d;
} m;

struct matrix power(struct matrix m, int n) {
	struct matrix m_;
	int a, b, c, d;

	if (n == 0) {
		m_.a = 1;
		m_.b = 0;
		m_.c = 0;
		m_.d = 1;
	} else {
		m_ = power(m, n / 2);
		a = m_.a;
		b = m_.b;
		c = m_.c;
		d = m_.d;
		m_.a = ((long long) a * a % M + (long long) c * b % M) % M;
		m_.b = ((long long) b * a % M + (long long) d * b % M) % M;
		m_.c = ((long long) a * c % M + (long long) c * d % M) % M;
		m_.d = ((long long) b * c % M + (long long) d * d % M) % M;
		if (n % 2 != 0) {
			a = m_.a;
			b = m_.b;
			c = m_.c;
			d = m_.d;
			m_.a = ((long long) a * m.a % M + (long long) c * m.b % M) % M;
			m_.b = ((long long) b * m.a % M + (long long) d * m.b % M) % M;
			m_.c = ((long long) a * m.c % M + (long long) c * m.d % M) % M;
			m_.d = ((long long) b * m.c % M + (long long) d * m.d % M) % M;
		}
	}
	return m_;
}

int main() {
	int a, b, n, x;

	scanf("%d%d%d%d", &a, &b, &n, &x);
	m.a = a;
	m.b = b;
	m.c = 0;
	m.d = 1;
	m = power(m, n);
	printf("%lld\n", (((long long) x * m.a % M) + m.b) % M);
	return 0;
}

#include <stdio.h>

#define M	1000000007

struct matrix {
	int a, b, c, d;
} m;

struct matrix power(struct matrix m, int n) {
	struct matrix m_;
	int a, b, c, d;

	if (n == 0) {
		m_.a = 1;
		m_.b = 0;
		m_.c = 0;
		m_.d = 1;
	} else {
		m_ = power(m, n / 2);
		a = m_.a;
		b = m_.b;
		c = m_.c;
		d = m_.d;
		m_.a = ((long long) a * a % M + (long long) c * b % M) % M;
		m_.b = ((long long) b * a % M + (long long) d * b % M) % M;
		m_.c = ((long long) a * c % M + (long long) c * d % M) % M;
		m_.d = ((long long) b * c % M + (long long) d * d % M) % M;
		if (n % 2 != 0) {
			a = m_.a;
			b = m_.b;
			c = m_.c;
			d = m_.d;
			m_.a = ((long long) a * m.a % M + (long long) c * m.b % M) % M;
			m_.b = ((long long) b * m.a % M + (long long) d * m.b % M) % M;
			m_.c = ((long long) a * m.c % M + (long long) c * m.d % M) % M;
			m_.d = ((long long) b * m.c % M + (long long) d * m.d % M) % M;
		}
	}
	return m_;
}

int main() {
	int a, b, x;
	long long n;

	scanf("%d%d%lld%d", &a, &b, &n, &x);
	m.a = a;
	m.b = b;
	m.c = 0;
	m.d = 1;
	m = power(m, n);
	printf("%lld\n", (((long long) x * m.a % M) + m.b) % M);
	return 0;
}

/*
   Sachin Chandani
   IIIT Hyderabad
   		*/

#include<stdio.h>
#include<limits.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
int min(int a,int b);
int cmp(const void *a,const void *b)
{
	return(*(int*)a-*(int*)b);

}
int min(int a,int b)
{
	return(a>b?b:a);
}

int main()
{
	long long int A,B,n,x;
	scanf("%lld%lld%lld%lld",&A,&B,&n,&x);
	long long int ans,temp;
	if(A==1)
	{
		printf("%lld",(x+(n*B)%1000000007)%1000000007);
		return 0;
	}
	ans=((long long int)(pow(A,n)))%1000000007;
	ans=((ans*x)%1000000007);
	temp=((B*(((long long int)(pow(A,n))-1)))/(A-1))%1000000007;
	ans=(ans+temp)%1000000007;
	printf("%lld",ans);
	return 0;
}

#include<stdio.h>
long long int a,b,n,x,y,z;
long long int mod = 1000000007;
long long int modpowfast(long long int base,long long int e)
{
	long long int ans=1;
	while(e>0)
	{
		if(e&1)
			ans=(ans*base)%mod;
		base=(base*base)%mod;
		e=e>>1;
	}
	return ans;
}

int main()
{
	long long int ans=0;
	scanf("%lld %lld %lld %lld",&a,&b,&n,&x);
	n=n%mod;
	if(a==1)
	{
		ans  =  (x + (n*b)%mod)%mod;
	}
	else
	{
		y = modpowfast(a,n);
		z = modpowfast(a-1,mod-2);
//		printf("%lld %lld\n",y,z);
		ans = ((y*x)%mod + (((y-1)*z)%mod)*b )%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

#include<stdio.h>
long long int a,b,n,x,y,z;
long long int mod = 1000000007;
long long int modpowfast(long long int base,long long int e)
{
	long long int ans=1;
	while(e>0)
	{
		if(e&1)
			ans=(ans*base)%mod;
		base=(base*base)%mod;
		e=e>>1;
	}
	return ans;
}

int main()
{
	long long int ans=0;
	scanf("%lld %lld %lld %lld",&a,&b,&n,&x);
	if(a==1)
	{
		ans  =  (x + (n*b)%mod)%mod;
	}
	else
	{
		y = modpowfast(a,n);
		z = modpowfast(a-1,mod-2);
//		printf("%lld %lld\n",y,z);
		ans = ((y*x)%mod + (((y-1)*z)%mod)*b )%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

#include<stdio.h>

unsigned long long int m=1000000007;
unsigned long long int bigmod(unsigned long long int x, unsigned long long int n)
{
    if(n==0) return 1;

    if(n%2==0)
    {
    unsigned long long int num= bigmod(x,n/2);
    return ((num%m)*(num%m))%m;
    }

    else
        return ((x%m)*(bigmod(x,n-1)%m))%m;

}

int main()
{
    unsigned long long int  sum1=0,sum2=0,sum=0,n,A,B,x;

    scanf("%llu %llu %llu %llu",&A,&B,&n,&x);

    sum1=bigmod(A,n)%m;
    sum2=(sum1-1)%m;

    sum1=((sum1%m)*(x%m))%m;
    sum2=((sum2%m)*(B%m))%m;

    sum2=((sum2%m)* (bigmod(A-1,m-2))%m)%m;

    sum=((sum1%m)+(sum2%m))%m;

    printf("%llu\n",sum%m);

    return 0;
}

#include <stdio.h>
# define m 1000000007
long long int power(long long int x,long long int y)
{
	if(y==0)
	return 1;
	else if(y%2==0)
	{
		long long int z;
		z=power(x,y/2)%m;
		return (z*z)%m;
	}
	else
	{
		long long int z;
		z=power(x,y/2)%m;
		return ((x%m*z%m)%m*z)%m;
	}
}
int main()
{
	long long int n,a,b,x,i,ans=0;
	scanf("%lld %lld %lld %lld",&a,&b,&n,&x);
//	for(i=0;i<n;i++)
//	{
		ans=ans+(power(a,n)-1);
		if(ans<0)
		ans=ans+m;
		ans=(ans%m*b%m)%m;
		ans=((ans%m)*power(a-1,m-2)%m)%m;
//	}
	ans=ans+(power(a,n)%m*x%m)%m;
	ans=ans%m;
	printf("%lld\n",ans);
	return 0;
}

#include <stdio.h>
# define m 1000000007
long long int power(long long int x,long long int y)
{
	if(y==0)
	return 1;
	else if(y%2==0)
	{
		long long int z;
		z=power(x,y/2)%m;
		return (z*z)%m;
	}
	else
	{
		long long int z;
		z=power(x,y/2)%m;
		return ((x%m*z%m)%m*z)%m;
	}
}
int main()
{
	long long int n,a,b,x,i,ans=0;
	scanf("%lld %lld %lld %lld",&a,&b,&n,&x);
//	for(i=0;i<n;i++)
//	{
		ans=(power(a,n)-1);
		if(ans<0)
		ans=ans+m;
		ans=(ans%m*b%m)%m;
		if(ans<0)
		ans+=m;
		if(a-1>0)
		ans=((ans%m)*power(a-1,m-2)%m)%m;
//	}
	ans=ans+(power(a,n)%m*x%m)%m;
	ans=ans%m;
	printf("%lld\n",ans);
	return 0;
}

#include <stdio.h>
# define m 1000000007
long long int power(long long int x,long long int y)
{
	if(y==0)
	return 1;
	else if(y%2==0)
	{
		long long int z;
		z=power(x,y/2)%m;
		return (z*z)%m;
	}
	else
	{
		long long int z;
		z=power(x,y/2)%m;
		return ((x%m*z%m)%m*z)%m;
	}
}
int main()
{
	long long int n,a,b,x,i,ans=0;
	scanf("%lld %lld %lld %lld",&a,&b,&n,&x);
//	for(i=0;i<n;i++)
//	{
		ans=(power(a,n)-1)%m;
		if(ans<0)
		ans=ans+m;
		ans=(ans%m*b%m)%m;
		if(ans<0)
		ans+=m;
		if(a-1>0)
		ans=((ans%m)*power(a-1,m-2)%m)%m;
		 ans=ans%m;
//	}
	ans=(ans+(power(a,n)%m*x%m)%m)%m;
	ans=ans%m;
	printf("%lld\n",ans);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

//input definitions
#define sd(x) scanf("%d",&x);
#define slld(x) scanf("%lld",&x);
#define ss(x) scanf("%s",x);
#define sf(x) scanf("%f",&x);
#define slf(x) scanf("%lf",&x);

//output definitions
#define pd(x) printf("%d",x);
#define plld(x) printf("%lld",x);
#define ps(x) printf("%s",x);
#define pf(x) printf("%f",x);
#define plf(x) printf("%lf",x);
#define pnl printf("\n");
#define psp printf(" ");

//define datatypes
typedef long long int ll;

//loops
#define upto(x) for(;i<=x;i++)
#define fl(i,a,b,c) for(i=a;i<=b;i+=c)
#define wl(x) while(x--)

#define MOD 1000000007

ll power(ll a, ll b){
	ll ans = 1;
	while(b > 0){
		if(b & 1){
			ans = (ans * a) % MOD;
		}
		a = (a*a) % MOD;
		b/=2;
	}
	return ans%MOD;
}

int main(void) {
	ll a,b,c,d,n,x;
	slld(a) slld(b) slld(n) slld(x)
	ll ans = (power(a,n) * x) % MOD;
	ans = (ans + (((((power(a,n) - 1 + MOD) % MOD) * power(a-1,MOD-2)) % MOD) * b) % MOD ) % MOD;
	plld(ans)
	return 0;

}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

//input definitions
#define sd(x) scanf("%d",&x);
#define slld(x) scanf("%lld",&x);
#define ss(x) scanf("%s",x);
#define sf(x) scanf("%f",&x);
#define slf(x) scanf("%lf",&x);

//output definitions
#define pd(x) printf("%d",x);
#define plld(x) printf("%lld",x);
#define ps(x) printf("%s",x);
#define pf(x) printf("%f",x);
#define plf(x) printf("%lf",x);
#define pnl printf("\n");
#define psp printf(" ");

//define datatypes
typedef long long int ll;

//loops
#define upto(x) for(;i<=x;i++)
#define fl(i,a,b,c) for(i=a;i<=b;i+=c)
#define wl(x) while(x--)

#define MOD 1000000007

ll power(ll a, ll b){
	ll ans = 1;
	if(b == 1)
		return a;
	while(b > 0){
		if(b & 1){
			ans = (ans * a) % MOD;
		}
		a = (a*a) % MOD;
		b/=2;
	}
	return ans%MOD;
}

int main(void) {
	ll a,b,c,d,n,x;
	slld(a) slld(b) slld(n) slld(x)
	ll ans = (power(a,n) * x) % MOD;
	ans = (ans + ((((power(a,n) - 1 + MOD) % MOD) * power(a-1,MOD-2)) % MOD * b) % MOD ) % MOD;
	plld(ans)
	return 0;

}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

//input definitions
#define sd(x) scanf("%d",&x);
#define slld(x) scanf("%lld",&x);
#define ss(x) scanf("%s",x);
#define sf(x) scanf("%f",&x);
#define slf(x) scanf("%lf",&x);

//output definitions
#define pd(x) printf("%d",x);
#define plld(x) printf("%lld",x);
#define ps(x) printf("%s",x);
#define pf(x) printf("%f",x);
#define plf(x) printf("%lf",x);
#define pnl printf("\n");
#define psp printf(" ");

//define datatypes
typedef long long int ll;

//loops
#define upto(x) for(;i<=x;i++)
#define fl(i,a,b,c) for(i=a;i<=b;i+=c)
#define wl(x) while(x--)

#define MOD 1000000007

ll power(ll a, ll b){
	ll ans = 1;
	while(b > 0){
		if(b & 1){
			ans = (ans * a) % MOD;
		}
		a = (a*a) % MOD;
		b/=2;
	}
	return ans%MOD;
}

int main(void) {
	ll a,b,c,d,n,x;
	slld(a) slld(b) slld(n) slld(x)
	if(n == 1){
		plld(((a*x)%MOD + b) % MOD)
	}
	else{
		ll ans = (power(a,n) * x) % MOD;
		ans = (ans + (((((power(a,n) - 1 + MOD) % MOD) * power(a-1,MOD-2)) % MOD) * b) % MOD ) % MOD;
		plld(ans)
	}
	return 0;

}

#include<stdio.h>
#include<string.h>
#include<math.h>
typedef unsigned long long LL;
LL m=1000000007;

LL bigmod(LL a,LL b, LL m)
{
    if(b==0)    return 1%m;
    LL x=bigmod(a,b/2,m);
    x=(x*x)%m;
    if(b%2==1)
        x=(x*a)%m;
    return x;
}
int main()
{
    LL n, a, b, x, f, ans, f2, f3;
    char  s[200010];
    scanf("%llu %llu %llu %llu",&a,&b,&n,&x);
    f = bigmod(a, n, m);
    f2 = (f * (x % m)) % m;
    if(a==1)
    {
        ans = (f2 + (b* (n%m) )% m) % m;
    }
    else
    {
        f3 = bigmod(a-1, m-2, m);
        ans = (f2+(b*((f-1)*f3)%m)%m)%m;
    }

    printf("%llu\n",ans);
    return 0;

}

#include <stdio.h>
typedef long long ll;
ll MOD = 1000000007 ;
ll MOD2 = 1000000006 ;

ll gcdExtended(ll a, ll b, ll *x, ll *y);

ll power(ll x, ll y, ll p) ;

// Function to find modulo inverse of a
ll modInverse(ll a, ll m)
{
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);

        // m is added to handle negative x
        ll res = (x%m + m) % m;
        return res ;

}

// C function for extended Euclidean Algorithm
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

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

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll main(ll argc, char const *argv[])
{
    ll A,B,n,x;
    scanf("%lld %lld %lld %lld",&A,&B,&n,&x);
    ll answer = 0;
    ll apart = 1;
    ll itna = n%(MOD2);
    if(itna==0)
    {
        printf("%lld\n",x%MOD);
    }
    else
    {
    ll second = 1;
    ll dot = power(A,n,MOD);
    answer += (dot*x%MOD)%MOD ;
    ll ert  = dot-1 ;
    ll gh = A-1 ;
    if(A!=1)
    {
    answer += (((modInverse(A-1,MOD)*ert)%MOD)*B)%MOD;
    }
    else
    {
        answer += (B*n)%MOD ;
    }
    //prllf("%lld\n",);
    printf("%lld\n",answer);
    }
    return 0;
}

#include <stdio.h>
typedef long long ll;
ll MOD = 1000000007 ;
ll MOD2 = 1000000006 ;

ll gcdExtended(ll a, ll b, ll *x, ll *y);

ll power(ll x, ll y, ll p) ;

// Function to find modulo inverse of a
ll modInverse(ll a, ll m)
{
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);

        // m is added to handle negative x
        ll res = (x%m + m) % m;
        return res ;

}

// C function for extended Euclidean Algorithm
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

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

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll main(ll argc, char const *argv[])
{
    ll A,B,n,x;
    scanf("%lld %lld %lld %lld",&A,&B,&n,&x);
    ll answer = 0;
    ll apart = 1;
    ll itna = n%(MOD2);
    if(itna==0)
    {
        printf("%lld\n",x%MOD);
    }
    else
    {
    ll second = 1;
    ll dot = power(A,itna,MOD);
    answer = (answer +((dot*x) % MOD))%MOD ;
    ll ert  = dot-1 ;
    ll gh = A-1 ;
    if(A!=1)
    {
    answer = (answer+(((modInverse(A-1,MOD)*ert)%MOD)*B)%MOD)%MOD;
    }
    else
    {
    //    printf("yele %lld\n\n",itna);
        answer = (answer + ((B*n)%MOD))%MOD ;
    }
    //prllf("%lld\n",);
    printf("%lld\n",answer);
    }
    return 0;
}

#include <stdio.h>
typedef long long ll;
ll MOD = 1000000007 ;
ll MOD2 = 1000000006 ;

ll gcdExtended(ll a, ll b, ll *x, ll *y);

ll power(ll x, ll y, ll p) ;

// Function to find modulo inverse of a
ll modInverse(ll a, ll m)
{
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);

        // m is added to handle negative x
        ll res = (x%m + m) % m;
        return res ;

}

// C function for extended Euclidean Algorithm
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

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

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll main(ll argc, char const *argv[])
{
    ll A,B,n,x;
    scanf("%lld %lld %lld %lld",&A,&B,&n,&x);
    ll answer = 0;
    ll apart = 1;
    ll itna = n%(MOD2);
    if(itna==0)
    {
        printf("%lld\n",x%MOD);
    }
    else
    {
    ll second = 1;
    ll dot = power(A,itna,MOD);
    answer += ((dot*x) % MOD) ;
    ll ert  = dot-1 ;
    ll gh = A-1 ;
    if(A!=1)
    {
    answer = (answer+(((modInverse(A-1,MOD)*ert)%MOD)*B))%MOD;
    }
    else
    {
        answer = (answer + (B*itna))%MOD ;
    }
    //prllf("%lld\n",);
    printf("%lld\n",answer);
    }
    return 0;
}

#include <stdio.h>
typedef long long ll;
ll MOD = 1000000007 ;
ll MOD2 = 1000000006 ;

ll gcdExtended(ll a, ll b, ll *x, ll *y);

ll power(ll x, ll y, ll p) ;

// Function to find modulo inverse of a
ll modInverse(ll a, ll m)
{
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);

        // m is added to handle negative x
        ll res = (x%m + m) % m;
        return res ;

}

// C function for extended Euclidean Algorithm
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

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

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll main(ll argc, char const *argv[])
{
    ll A,B,n,x;
    scanf("%lld %lld %lld %lld",&A,&B,&n,&x);
    ll answer = 0;
    ll apart = 1;
    ll itna = n%(MOD2);
    if(itna==0)
    {
        printf("%lld\n",x%MOD);
    }
    else
    {
    ll second = 1;
    ll dot = power(A,itna,MOD);
    answer += (dot*x%MOD)%MOD ;
    ll ert  = dot-1 ;
    ll gh = A-1 ;
    if(A!=1)
    {
    answer += (((modInverse(A-1,MOD)*ert)%MOD)*B)%MOD;
    }
    else
    {
        answer += (B*n)%MOD ;
    }
    //prllf("%lld\n",);
    printf("%lld\n",answer);
    }
    return 0;
}

#include <stdio.h>
typedef long long ll;
ll MOD = 1000000007 ;
ll MOD2 = 1000000006 ;

ll gcdExtended(ll a, ll b, ll *x, ll *y);

ll power(ll x, ll y, ll p) ;

// Function to find modulo inverse of a
ll modInverse(ll a, ll m)
{
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);

        // m is added to handle negative x
        ll res = (x%m + m) % m;
        return res ;

}

// C function for extended Euclidean Algorithm
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

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

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll main(ll argc, char const *argv[])
{
    ll A,B,n,x;
    scanf("%lld %lld %lld %lld",&A,&B,&n,&x);
    ll answer = 0;
    ll apart = 1;
    ll itna = n%(MOD2);
    if(itna==0)
    {
        printf("%lld\n",x%MOD);
    }
    else
    {
    ll second = 1;
    ll dot = power(A,itna,MOD);
    answer += (dot*x%MOD)%MOD ;
    ll ert  = dot-1 ;
    ll gh = A-1 ;
    if(A!=1)
    {
    answer += (((modInverse(A-1,MOD)*ert)%MOD)*B)%MOD;
    }
    else
    {
        answer += (B*itna)%MOD ;
    }
    //prllf("%lld\n",);
    printf("%lld\n",answer);
    }
    return 0;
}

#include <stdio.h>
typedef long long ll;
ll MOD = 1000000007 ;
ll MOD2 = 1000000006 ;

ll gcdExtended(ll a, ll b, ll *x, ll *y);

ll power(ll x, ll y, ll p) ;

// Function to find modulo inverse of a
ll modInverse(ll a, ll m)
{
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);

        // m is added to handle negative x
        ll res = (x%m + m) % m;
        return res ;

}

// C function for extended Euclidean Algorithm
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

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

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll main(ll argc, char const *argv[])
{
    ll A,B,n,x;
    scanf("%lld %lld %lld %lld",&A,&B,&n,&x);
    ll answer = 0;
    ll apart = 1;
    ll itna = n%(MOD2);
    if(itna==0)
    {
        printf("%lld\n",x%MOD);
    }
    else
    {
    ll second = 1;
    ll dot = power(A,itna,MOD);
    answer = (answer +((dot*x) % MOD))%MOD ;
    ll ert  = dot-1 ;
    ll gh = A-1 ;
    if(A!=1)
    {
    answer = (answer+(((modInverse(A-1,MOD)*ert)%MOD)*B))%MOD;
    }
    else
    {
        answer = (answer + (B*itna))%MOD ;
    }
    //prllf("%lld\n",);
    printf("%lld\n",answer);
    }
    return 0;
}

long long int modular_pow(long long int base, long long int exponent, long long int modulus)
{
    long long int result = 1;
    while (exponent > 0)
    {
        if (exponent % 2 == 1)
            result = (result * base) % modulus;
        exponent = exponent >> 1;
        base = (base * base) % modulus;
    }
    return result;
}
int powercal(int x, unsigned int y)
{
    int res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = res*x;

        // n must be even now
        y = y>>1; // y = y/2
        x = x*x;  // Change x to x^2
    }
    return res;
}
int main ()
{
    long long int  n,a,b,x,ans,e12,ef,e,e1,e2,pr,en;
    long long int p=1000000007;
    scanf ("%I64d %I64d %I64d %I64d",&a,&b,&n,&x);
    //printf ("%I64d\n",(-1)%3);
    if (a!=1)
    {
        e1=b%p;
        pr=modular_pow(a,n,p);//(a^n)%p
        e2=(pr+(p-1))%p;
        printf ("%I64d ",e2);// (a^n-1) %p
        en=modular_pow(a-1,p-2,p);
        e2=((e2%p)*en)%p;
        e12=(e1*e2)%p;
        e=((x%p)*pr)%p;
        ef=(e12+e)%p;
        printf ("%I64d",ef);
        return 0;
    }
    else
    {
        e=((n%p)*(b%p))%p;
        ef=(e+(x%p))%p;
      printf ("%I64d",ef);
      return 0;
    }
}

long long int modular_pow(long long int base, long long int exponent, long long int modulus)
{
    long long int result = 1;
    while (exponent > 0)
    {
        if (exponent % 2 == 1)
            result = (result * base) % modulus;
        exponent = exponent >> 1;
        base = (base * base) % modulus;
    }
    return result;
}
int powercal(int x, unsigned int y)
{
    int res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = res*x;

        // n must be even now
        y = y>>1; // y = y/2
        x = x*x;  // Change x to x^2
    }
    return res;
}
int main ()
{
    long long int  n,a,b,x,ans,e12,ef,e,e1,e2,pr,an,en;
    long long int p=1000000007;
    scanf ("%I64d %I64d %I64d %I64d",&a,&b,&n,&x);
    //printf ("%I64d\n",(-1)%3);
    if (a!=1)
    {
        an=powercal(a,n);
        en=(an-1)/(a-1);
        e1=((b%p) * (en%p))%p;
        pr=modular_pow(a,n,p);
        e2=(pr*(x%p)) %p;
        ef=(e1+e2)%p;
        printf ("%I64d",ef);
        return 0;
    }
    else
    {
        e=((n%p)*(b%p))%p;
        ef=(e+(x%p))%p;
      printf ("%I64d",ef);
      return 0;
    }
}

long long int modular_pow(long long int base, long long int exponent, long long int modulus)
{
    long long int result = 1;
    while (exponent > 0)
    {
        if (exponent % 2 == 1)
            result = (result * base) % modulus;
        exponent = exponent >> 1;
        base = (base * base) % modulus;
    }
    return result;
}
int main ()
{
    long long int  n,a,b,x,ans,e12,ef,e,e1,e2,pr;
    long long int p=1000000007;
    scanf ("%I64d %I64d %I64d %I64d",&a,&b,&n,&x);
    //printf ("%I64d\n",(-1)%3);
    if (a!=1)
    {
        e1=(b/(a-1))%p;
        pr=modular_pow(a,n,p);
        e2=(pr+(p-1))%p;
        e12=(e1*e2)%p;
        e=((x%p)*pr)%p;
        ef=(e12+e)%p;
        printf ("%I64d",ef);
        return 0;
    }
    else
    {
        e=((n%p)*(b%p))%p;
        ef=(e+(x%p))%p;
      printf ("%I64d",ef);
      return 0;
    }
}