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 D{
	
	public static final long P = 1000000007; 
	
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);  
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        
      	long a = sc.nextInt();
      	long b = sc.nextInt();
      	long n = sc.nextLong();
      	long x = sc.nextInt();
      	
      	if (a == 0) {
      		out.println(b);
      	} if (a == 1) {
      		long w = (x+((n%P)*b)%P)%P;
      		out.println(w);
      	} else {
      		long p = 1;
          	long aa = a;
          	long m = n;
          	while (m > 0) {
          		if ((m&1) != 0) {
          			p = (p*aa)%P;
          		}
          		aa = (aa*aa)%P;
          		m >>= 1;
          	}
          	long w = (p*x)%P;
          	p = (p+P-1)%P;
          	long d;
          	
          	long r0 = P;
          	long r1 = a-1;
          	long s0 = 0;
          	long s1 = 1;
         	while (r1 > 0) {
          		long q = r0/r1;
          		long r = r0 - q*r1;
          		r0 = r1;
          		r1 = r;          		
          		long s = s0-q*s1;
          		s0 = s1;
          		s1 = s;          		
          	}
          	        	
          	d = (s0+P)%P;
          	w = (w+(((p*d)%P)*b)%P)%P;
          	out.println(w);
      	}                     
                
        out.close();
        sc.close();
    }
}