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;
long long mod = 1000000007LL;
long long n, a, b, x;
vector<vector<long long> > mul(vector<vector<long long> > p,
                               vector<vector<long long> > q) {
  vector<vector<long long> > re(2, vector<long long>(2, 0LL));
  for (long long i = 0; i < 2; i++) {
    for (long long j = 0; j < 2; j++) {
      for (long long k = 0; k < 2; k++) {
        re[i][j] += ((p[i][k] * q[k][j]) % mod);
        re[i][j] %= mod;
      }
    }
  }
  return re;
}
vector<vector<long long> > f(long long n, vector<vector<long long> > mat) {
  if (n == 1LL) {
    return mat;
  }
  vector<vector<long long> > re = f(n / 2, mat);
  re = mul(re, re);
  if (n % 2 == 1LL) re = mul(re, mat);
  return re;
}
int main() {
  cin >> a >> b >> n >> x;
  vector<vector<long long> > re(2, vector<long long>(2, 0));
  re[0][0] = a;
  re[0][1] = b;
  re[1][0] = 0LL;
  re[1][1] = 1LL;
  re = f(n, re);
  long long ans = 0;
  ans = (re[0][0] * x) % mod;
  ans = (ans + re[0][1]) % mod;
  cout << ans << endl;
  return 0;
}
