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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 3e6;
const long long mod = 1e9 + 7;
const long double PI = acos((long double)-1);
long long pw(long long a, long long b, long long md = mod) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (a * res) % md;
    }
    a = (a * a) % md;
    b >>= 1;
  }
  return (res);
}
long long a, b, n, x;
struct matrix {
  vector<vector<int> > mat;
  int n, m;
  matrix(int N, int M) {
    n = N, m = M;
    mat.resize(n);
    for (int i = 0; i < n; i++) mat[i].resize(m);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) mat[i][j] = 0;
  }
  friend matrix operator*(matrix &A, matrix &B) {
    assert(A.m == B.n);
    int &n = A.n, &m = B.m;
    int &K = A.m;
    matrix C(n, m);
    auto &c = C.mat;
    auto &a = A.mat;
    auto &b = B.mat;
    for (int i = 0; i < n; i++)
      for (int k = 0; k < K; k++)
        for (int j = 0; j < m; j++)
          c[i][j] = (1LL * c[i][j] + 1LL * a[i][k] * b[k][j]) % mod;
    return (C);
  }
  friend matrix operator^(matrix a, long long b) {
    matrix res(a.n, a.n);
    for (int i = 0; i < a.n; i++) res.mat[i][i] = 1;
    while (b) {
      if (b & 1) res = a * res;
      b >>= 1;
      a = a * a;
    }
    return (res);
  }
};
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> a >> b >> n >> x;
  matrix m(2, 2);
  m.mat[0][0] = m.mat[1][0] = 1;
  m.mat[1][1] = a;
  m = m ^ n;
  matrix ans(2, 1);
  ans.mat[0][0] = b;
  ans.mat[1][0] = x;
  ans = m * ans;
  cout << ans.mat[1][0];
  return (0);
}
