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;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const int N = 3e5 + 5;
const long long M = 1e9 + 7;
long long power(long long x, long long y) {
  x %= M;
  long long ans = 1;
  while (y) {
    if (y & 1) ans = (ans * x) % M;
    y >>= 1LL;
    x = (x * x) % M;
  }
  return ans;
}
long long ad(long long a, long long b) { return ((a % M + b % M) % M); }
long long sub(long long a, long long b) { return ((a % M - b % M + M) % M); }
long long mul(long long a, long long b) { return (((a % M) * (b % M)) % M); }
long long divi(long long a, long long b) {
  return (mul(a, power(b, M - 2)) % M);
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long a, b, n, x;
  cin >> a >> b >> n >> x;
  long long sum = 0;
  if (a == 1) {
    sum = n;
  }
  long long ans = mul(b, (a == 1 ? sum : divi(sub(power(a, n), 1), sub(a, 1))));
  ans = ad(ans, mul(x, power(a, n)));
  cout << ans;
  return 0;
}
