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 MAXA = 1e9 + 9;
const int MAXB = 1e9 + 9;
const int MAXX = 1e9 + 9;
const long long MAXN = 1e18 + 8;
int A, B, X;
long long N;
vector<vector<int> > matMul(const vector<vector<int> > &a,
                            const vector<vector<int> > &b) {
  assert(a[0].size() == b.size());
  vector<vector<int> > res(a.size(), vector<int>(b[0].size()));
  for (int i = 0; i < a.size(); ++i)
    for (int j = 0; j < b[0].size(); ++j)
      for (int k = 0; k < a[0].size(); ++k)
        (res[i][j] += 1LL * a[i][k] * b[k][j] % MOD) %= MOD;
  return res;
}
vector<vector<int> > matPow(vector<vector<int> > a, long long p) {
  assert(a.size() == a[0].size());
  vector<vector<int> > res(a.size(), vector<int>(a[0].size()));
  for (int i = 0; i < a.size(); ++i) res[i][i] = 1;
  while (p) {
    if (p & 1LL) res = matMul(res, a);
    p >>= 1LL;
    a = matMul(a, a);
  }
  return res;
}
void solve() {
  vector<vector<int> > trans(2, vector<int>(2));
  trans = {{A, B}, {0, 1}};
  vector<vector<int> > val(2, vector<int>(1));
  val = {{X}, {1}};
  val = matMul(matPow(trans, N), val);
  cout << val[0][0] << endl;
}
int main() {
  cin >> A >> B >> N >> X;
  solve();
  return 0;
}
