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 long long INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int N = 1e3 + 7;
const double PI = acos(-1.);
const long long MOD = 1e9 + 7;
const int mod = 1e6 + 3;
vector<vector<long long> > mul(vector<vector<long long> > a,
                               vector<vector<long long> > b) {
  vector<vector<long long> > ret(a.size(), vector<long long>(b[0].size(), 0));
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < b[0].size(); j++) {
      for (int k = 0; k < b.size(); k++) {
        ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]) % MOD;
      }
    }
  }
  return ret;
}
vector<vector<long long> > qpow(vector<vector<long long> > a, long long b) {
  vector<vector<long long> > ret(3, vector<long long>(3, 0));
  for (int i = 0; i <= 2; i++) ret[i][i] = 1;
  while (b) {
    if (b & 1) ret = mul(ret, a);
    a = mul(a, a);
    b >>= 1;
  }
  return ret;
}
int main() {
  long long A, B, n, x;
  cin >> A >> B >> n >> x;
  vector<vector<long long> > a(3, vector<long long>(1, 0));
  vector<vector<long long> > base(3, vector<long long>(3, 0));
  a[0][0] = (A * x + B) % MOD;
  a[1][0] = x % MOD;
  a[2][0] = B;
  base[0][0] = A;
  base[0][2] = base[1][1] = base[2][2] = 1;
  base = qpow(base, n - 1);
  vector<vector<long long> > ret = mul(base, a);
  cout << ret[0][0] % MOD << endl;
}
