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 m = 1e9 + 7;
const int N = 3e5 + 15;
const int64_t INF = 100000000000000018LL;
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
               greater<pair<long long, long long>>>
    pq;
vector<vector<long long>> graph(N);
vector<long long> collect;
map<long long, long long> mpp;
set<pair<long long, long long>> s;
set<long long> second;
long long odd = 0, even = 0;
long long pow(long long a, long long b, long long m) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
long long inv(long long a) { return pow(a, m - 2, m); }
void dfs(long long ind, vector<bool>& visited) {
  visited[ind] = true;
  for (auto it : graph[ind]) {
    {
      if (!visited[it]) dfs(it, visited);
    }
  }
}
bool isPowerOfTwo(long long n) {
  if (n == 0) return false;
  return (ceil(log2(n)) == floor(log2(n)));
}
void solve() {
  long long a, b, n, x;
  cin >> a >> b >> n >> x;
  long long ans = pow(a, n, m);
  n = n % m;
  long long aa = ans * x;
  if (aa < 0) aa += m;
  aa = aa % m;
  long long aa1 = 1;
  if (a == 1) {
    long long z1 = b * n;
    z1 = z1 % m;
    cout << (x + z1) % m;
    return;
  }
  aa1 = ((ans - 1 + m) % m) * inv(a - 1);
  aa1 = aa1 % m;
  if (aa1 < 0) aa1 += m;
  aa1 = aa1 * b;
  cout << (aa + aa1 + m) % m << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
}
