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

Input

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

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

Output

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

Examples

Input

3 4 1 1


Output

7


Input

3 4 2 1


Output

25


Input

3 4 3 1


Output

79
import java.io.*;
import java.util.*;
public class Main {
	static int mod=1000000007;
	static long[] a2i=new long[60];
	static long[] a2isum=new long[60];
	public static void main(String[] args) {
		Scanner kb=new Scanner(System.in);
		long a=kb.nextLong();
		long b=kb.nextLong();
		long n=kb.nextLong();
		long x=kb.nextLong();
		a2i[0]=a;
		for(int i=1;i<60;i++){
			a2i[i]=(a2i[i-1]*a2i[i-1])%mod;
		}
		a2isum[0]=1L;
		for(int i=1;i<60;i++){
			a2isum[i]=(a2isum[i-1]*((a2i[i-1]+1)%mod))%mod;
		}
		long an=pow(a,n);
		//System.out.println(an);
		long ansum=sumPowUpTo(a,n);
		//System.out.println(ansum);
		System.out.println(((an*x)%mod+(ansum*b)%mod)%mod);
	}
	private static long sumPowUpTo(long a, long n) {
		if(n==0){
			return 0L;
		}
		else{
			long hob=Long.highestOneBit(n);
			int pow=Long.numberOfTrailingZeros(hob);
			return (a2isum[pow]+(a2i[pow]*sumPowUpTo(a,n-hob))%mod)%mod;
		}
	}
	private static long pow(long a, long n) {
		long sum=1;
		for(int i=0;i<60;i++){
			long bit=1L<<i;
			if((bit&n)!=0){
				sum*=a2i[i];
				sum%=mod;
				//System.out.println(sum);
			}
		}
		return sum;
	}

}
