#include <bits/stdc++.h>
long long n, a, b, c, p, q, ans, x;
const int P = 1000000007;
struct matrix {
  long long a[2][2];
} f, g;
matrix cf(matrix u, matrix v) {
  matrix ans;
  int i, j, k;
  for (i = 0; i <= 1; i++)
    for (j = 0; j <= 1; j++) ans.a[i][j] = 0;
  for (i = 0; i <= 1; i++)
    for (j = 0; j <= 1; j++)
      for (k = 0; k <= 1; k++) (ans.a[i][j] += u.a[i][k] * v.a[k][j]) %= P;
  return ans;
}
matrix ksm(long long x) {
  matrix ans;
  if (x == 1) {
    ans = f;
    return ans;
  }
  ans = ksm(x / 2);
  ans = cf(ans, ans);
  if (x % 2) ans = cf(ans, f);
  return ans;
}
int main() {
  scanf("%I64d%I64d%I64d%I64d", &a, &b, &n, &x);
  f.a[0][0] = a;
  f.a[0][1] = 1;
  f.a[1][0] = 0;
  f.a[1][1] = 1;
  g = ksm(n);
  long long ans = (x * g.a[0][0] + b * g.a[0][1]) % P;
  printf("%I64d\n", ans);
}

### Prompt

Please create a solution in cpp to the following problem:

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

### Response

```cpp
#include <bits/stdc++.h>
long long n, a, b, c, p, q, ans, x;
const int P = 1000000007;
struct matrix {
  long long a[2][2];
} f, g;
matrix cf(matrix u, matrix v) {
  matrix ans;
  int i, j, k;
  for (i = 0; i <= 1; i++)
    for (j = 0; j <= 1; j++) ans.a[i][j] = 0;
  for (i = 0; i <= 1; i++)
    for (j = 0; j <= 1; j++)
      for (k = 0; k <= 1; k++) (ans.a[i][j] += u.a[i][k] * v.a[k][j]) %= P;
  return ans;
}
matrix ksm(long long x) {
  matrix ans;
  if (x == 1) {
    ans = f;
    return ans;
  }
  ans = ksm(x / 2);
  ans = cf(ans, ans);
  if (x % 2) ans = cf(ans, f);
  return ans;
}
int main() {
  scanf("%I64d%I64d%I64d%I64d", &a, &b, &n, &x);
  f.a[0][0] = a;
  f.a[0][1] = 1;
  f.a[1][0] = 0;
  f.a[1][1] = 1;
  g = ksm(n);
  long long ans = (x * g.a[0][0] + b * g.a[0][1]) % P;
  printf("%I64d\n", ans);
}

```