#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int maxlog = 25;
const long long mod = 1e9 + 7;
const int sq = 720;
const int inf = 1e9;
long long powmod(long long a, long long n) {
  if (n == 0) return 1;
  long long x = powmod(a, n / 2);
  long long cur = (x * x) % mod;
  if (n & 1) cur = (cur * a) % mod;
  return cur;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cout.precision(20);
  long long a, b, n, x;
  cin >> a >> b >> n >> x;
  if (a == 1) {
    cout << (x + (n % mod) * b) % mod;
    return 0;
  }
  long long ans =
      ((((b * (powmod(a, n) - 1)) % mod) * powmod(a - 1, mod - 2)) % mod +
       (powmod(a, n) * x) % mod) %
      mod;
  cout << ans;
  return 0;
}
