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;
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.push_back(move(x));
  return v;
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << '\n';
  err(++it, args...);
}
long long A, B, N, X;
long long e[62][2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> A >> B >> N >> X;
  e[0][0] = A;
  e[0][1] = B;
  for (int i = 1; i < 62; i++) {
    e[i][0] = (e[i - 1][0] * e[i - 1][0]) % 1000000007LL;
    e[i][1] = ((e[i - 1][0] + 1) * e[i - 1][1]) % 1000000007LL;
  }
  long long a = 1;
  long long b = 0;
  for (int i = 62 - 1; i >= 0; i--) {
    long long x = 1LL << i;
    if (x <= N) {
      N -= x;
      long long ap = a * e[i][0];
      long long bp = a * e[i][1] + b;
      a = ap % 1000000007LL;
      b = bp % 1000000007LL;
    }
  }
  cout << (a * X + b) % 1000000007LL << endl;
}
