#include <bits/stdc++.h>
using namespace std;
unsigned long long pwr(unsigned long long a, unsigned long long b,
                       unsigned long long mod) {
  a %= mod;
  if (a < 0) a += mod;
  unsigned long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return ans;
}
unsigned long long pwr(unsigned long long a, unsigned long long b) {
  unsigned long long ans = 1;
  while (b) {
    if (b & 1) ans *= a;
    a *= a;
    b /= 2;
  }
  return ans;
}
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  while (b) {
    unsigned long long temp = a;
    a = b;
    b = temp % b;
  }
  return a;
}
unsigned long long lcm(unsigned long long a, unsigned long long b) {
  return (a / gcd(a, b)) * b;
}
unsigned long long modularInverse(unsigned long long a, unsigned long long m) {
  return pwr(a, m - 2, m);
}
int main(int argc, char const *argv[]) {
  unsigned long long a, b, n, x;
  cin >> a >> b >> n >> x;
  if (a != 1) {
    unsigned long long t1 = pwr(a, n, 1000000007);
    unsigned long long result =
        ((((t1 - 1) % 1000000007 * b) % 1000000007 *
          (modularInverse(a - 1, 1000000007) % 1000000007)) %
             1000000007 +
         (t1 * (x % 1000000007)) % 1000000007) %
        1000000007;
    cout << result;
  } else {
    unsigned long long result =
        ((b % 1000000007 * (n % 1000000007)) % 1000000007 + x) % 1000000007;
    cout << result;
  }
  return 0;
}
