#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int mod = 1000 * 1000 * 1000 + 7;
const long long inf = 1e18;
long long M = mod;
long long bigmod(long long N, long long P) {
  if (P == 0) return 1;
  if (P % 2 == 0) {
    long long ret = bigmod(N, P / 2);
    return ((ret % M) * (ret % M)) % M;
  } else
    return ((N % M) * (bigmod(N, P - 1) % M)) % M;
}
long long a, b, c, d, e, f, g, h, l, m, n, p, q, k, r, t, u, w, x, y, z,
    arr[100005] = {0}, ara[100005] = {0}, lo = inf, hi = 0;
string s, s2;
vector<long long> v, v2, v3;
int main() {
  cin >> a >> b >> n >> x;
  if (a == 1) {
    cout << (x + ((b % mod) * (n % mod)) % mod) % mod;
    return 0;
  }
  long long ans = 0;
  p = ((x * bigmod(a, n)) % mod +
       ((b * (bigmod(a, n) - 1)) % mod) * (bigmod(a - 1, mod - 2) % mod)) %
      mod;
  cout << p % mod;
}
