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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        static final long mod = (long) (1000000007);

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long A, B, n, x;
            A = in.nextLong();
            B = in.nextLong();
            n = in.nextLong();
            x = in.nextLong();
            x %= mod;
            long p, q;
            if (A == 1) {
                p = x;
                B %= mod;
                n %= mod;
                q = (n * B);
                q %= mod;
            } else {
                p = power(A, n) * x;
                p %= mod;
                q = (power(A, n) - 1) * inverse(A - 1);
                q %= mod;
                q *= B;
                q %= mod;
            }
            out.println((p + q) % mod);
        }

        private long power(long base, long expo) {
            long res = 1l;
            base %= mod;
            while (expo > 0) {
                if (expo % 2 == 1l) {
                    res = res * base;
                    res %= mod;
                }
                expo >>= 1l;
                base = base * base;
                base %= mod;
            }
            return res % mod;
        }

        private long inverse(long x) {
            return power(x, mod - 2);
        }

    }
}

