#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1);
long long int modpow(long long int a, long long int x) {
  int res = 1;
  while (x > 0)
    if (x & 1) {
      res = (res * a) % 1000000007;
      --x;
    } else {
      a = (a * a) % 1000000007;
      x >>= 1;
    }
  return res % 1000000007;
}
struct sx {};
bool cmp() {}
long long t1, t2, t3, t4, t5;
set<int> si;
vector<int> vi;
bool c;
int main() {
  long long a, b, x;
  long long n;
  cin >> a >> b >> n >> x;
  if (a == 1) {
    t1 = (x + ((n % 1000000007) * b) % 1000000007) % 1000000007;
    cout << t1;
    return 0;
  }
  t1 = (modpow(a, n) * x) % 1000000007;
  t2 = (modpow(a, n)) - 1LL;
  if (t2 < 0) t2 += 1000000007;
  t2 = (t2 * (modpow(a - 1LL, 1000000005LL))) % 1000000007;
  t2 = (t2 * b) % 1000000007;
  t3 = (t1 + t2) % 1000000007;
  cout << t3;
}
