#include // #include using namespace std; // using namespace atcoder; #define rep2(i,m,n) for (int i = (m); i < (n); ++i) #define rep(i,n) rep2(i,0,n) #define debug(x) cout << x << endl; typedef long long int ll; typedef long double ld; typedef pair P; template struct V : vector { using vector::vector; }; V() -> V; V(size_t) -> V; template V(size_t, T) -> V; template vector make_vec(size_t n, T a) { return vector(n, a); } template auto make_vec(size_t n, Ts... ts) { return vector(n, make_vec(ts...)); } template ostream &operator<<(ostream &os, const vector &v) { for (auto &e : v) os << e << ' '; return os; } struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const int INF = 1<<30; const ll LINF = 1LL<<61; const ll MOD = 1000000007; // using mint = modint1000000007; struct mint { ll x; mint(ll x = 0) : x(x % MOD) {} mint& operator+=(const mint rh) { if((x += rh.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint rh) { if((x += MOD-rh.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint rh) { (x *= rh.x) %= MOD; return *this; } mint operator+(const mint rh) const { return mint(*this) += rh; } mint operator-(const mint rh) const { return mint(*this) -= rh; } mint operator*(const mint rh) const { return mint(*this) *= rh; } mint pow(ll k) const { if(!k) return 1; mint a = x; mint res = 1; while(k) { if(k & 1) res *= a; k >>= 1; a *= a; } return res; } mint inv() const { return pow(MOD-2); } mint& operator/=(const mint rh) { return *this *= rh.inv(); } mint operator/(const mint rh) { return mint(*this) /= rh; } }; //2*2正方行列 struct matrix { mint a, b, c, d; matrix(mint a, mint b, mint c, mint d) : a(a), b(b), c(c), d(d) {} matrix& operator*=(const matrix rh) { mint p = rh.a, q = rh.b, r = rh.c, s = rh.d; mint na, nb, nc, nd; na = a*p + b*r; nb = a*q + b*s; nc = c*p + d*r; nd = c*q + d*s; a = na; b = nb; c = nc; d = nd; return *this; } matrix operator*(const matrix rh) const { return matrix(*this) *= rh; } }; matrix power(matrix x, ll k) { if(k <= 1) { return x; } matrix res = x; k--; while(k) { if(k & 1) res = (res * x); k >>= 1; x = (x * x); } return res; } int main() { ll a, b, n; cin >> a >> b >> n; mint a1(2), a2(2*a); if(n == 0) { cout << 2 << endl; return 0; } if(n == 1) { cout << a * 2 << endl; return 0; } matrix s(mint(2*a), mint(mint(b)-mint(a*a)), mint(1), mint(0)); matrix p = power(s, n); mint ans = p.c * a2 + p.d * a1; cout << ans.x << endl; return 0; }