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 oo = 999999999;
const double PI = 3.1415931;
const double eps = 1e-9;
const int mod = 1000000000 + 7;
long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long extgcd(long long a, long long b, long long &x, long long &y) {
  long long g = a;
  x = 1;
  y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
long long invMod(long long a, long long m) {
  long long x, y;
  if (extgcd(a, m, x, y) == 1)
    return (x + m) % m;
  else
    return 0;
}
long long fastPow(long long base, long long power) {
  if (power == 0) return 1LL;
  long long cur = fastPow(base, power / 2) % mod;
  cur *= cur;
  cur %= mod;
  if (power % 2) cur *= base;
  cur %= mod;
  return cur;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, a, b, x;
  cin >> a >> b >> n >> x;
  if (a == 1) {
    x %= mod;
    n %= mod;
    n *= a;
    n %= mod;
    n *= b;
    n %= mod;
    n += x;
    n %= mod;
    cout << n << endl;
    return 0;
  }
  long long ans = fastPow(a, n) % mod;
  ans *= x;
  ans %= mod;
  long long ans2 = fastPow(a, n) - 1LL + mod;
  ans2 %= mod;
  ans2 *= b;
  ans2 %= mod;
  ans2 *= invMod(a - 1, mod);
  ans2 %= mod;
  ans += ans2;
  ans %= mod;
  cout << ans << endl;
  return 0;
}
