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
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SZ = 2;
struct Matrix {
  int m[SZ][SZ];
  Matrix() {
    for (int i = 0; i < SZ; i++)
      for (int j = 0; j < SZ; j++) m[i][j] = 0;
  }
  Matrix(int val) {
    for (int i = 0; i < SZ; i++)
      for (int j = 0; j < SZ; j++) m[i][j] = 0;
    for (int i = 0; i < SZ; i++) m[i][i] = val;
  }
};
Matrix operator*(const Matrix &a, const Matrix &b) {
  Matrix res;
  for (int i = 0; i < SZ; i++)
    for (int j = 0; j < SZ; j++)
      for (int k = 0; k < SZ; k++)
        res.m[i][j] = (res.m[i][j] + a.m[i][k] * 1ll * b.m[k][j]) % MOD;
  return res;
}
Matrix binPow(Matrix a, long long k) {
  Matrix res(1);
  while (k) {
    if (k & 1) res = res * a;
    a = a * a;
    k >>= 1;
  }
  return res;
}
int main() {
  int A, B, x;
  long long n;
  cin >> A >> B >> n >> x;
  Matrix M;
  M.m[0][0] = A;
  M.m[0][1] = B;
  M.m[1][0] = 0;
  M.m[1][1] = 1;
  Matrix T = binPow(M, n);
  cout << (T.m[0][0] * 1ll * x + T.m[0][1]) % MOD << endl;
  return 0;
}
