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;
string bin_conv(long long int dec) {
  string tmp = "";
  while (dec > 0) {
    if (dec % 2 == 1)
      tmp += "1";
    else
      tmp += "0";
    dec /= 2;
  }
  reverse(tmp.begin(), tmp.end());
  return tmp;
}
long long int fast_expo(long long int b, long long int p) {
  string bin = bin_conv(p);
  long long int res = 1;
  for (int i = 0; i < bin.size(); i++) {
    res = (res * res) % 1000000007;
    if (bin[i] == '1') res = (res * b) % 1000000007;
  }
  return res;
}
long long int bigmod(long long int b, long long int p) {
  if (p == 1) return (b % 1000000007);
  long long int ret = bigmod(b, p / 2);
  ret = (ret * ret) % 1000000007;
  if (p % 2 == 1) ret = (ret * b) % 1000000007;
  return ret;
}
int main() {
  int kase = 1;
  long long int a, b, n, x;
  while (cin >> a >> b >> n >> x) {
    long long int a_n = fast_expo(a, n);
    long long int mul_inv = bigmod(a - 1, 1000000007 - 2);
    long long int ans = (a_n * x) % 1000000007;
    ans = (ans + (((a_n - 1) * b) % 1000000007 * mul_inv)) % 1000000007;
    if (a == 1)
      ans = (x % 1000000007 + n % 1000000007 * b % 1000000007) % 1000000007;
    if (n == 0) ans = x;
    printf("%lld\n", ans);
  }
}
