#include using namespace std; const long long MOD = 1e9 + 7; typedef vector vec; typedef vector matrix; matrix eye(int n) { matrix mat(n, vec(n)); for (int i = 0; i < n; i++) { mat[i][i] = 1; } return mat; } matrix zeros(int r, int c) { return matrix(r, vec(c)); } matrix zeros(int n) { return zeros(n, n); } matrix add(const matrix &a, const matrix &b) { matrix c = zeros(a.size(), a[0].size()); for (int i = 0; i < c.size(); i++) { for (int j = 0; j < c[0].size(); j++) { c[i][j] = a[i][j] + b[i][j]; } } return c; } matrix mul(const matrix &a, const matrix &b) { matrix c = zeros(a.size(), b[0].size()); for (int i = 0; i < a.size(); i++) { for (int k = 0; k < b.size(); k++) { for (int j = 0; j < b[0].size(); j++) { c[i][j] += a[i][k] * b[k][j]; } } } return c; } matrix modmul(const matrix &a, const matrix &b, long long mod) { matrix c = zeros(a.size(), b[0].size()); for (int i = 0; i < a.size(); i++) { for (int k = 0; k < b.size(); k++) { for (int j = 0; j < b[0].size(); j++) { c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % mod; } } } return c; } matrix pow(const matrix &a, long long p) { matrix ret = eye(a.size()); matrix x = a; while (p) { if (p & 1) ret = mul(ret, x); x = mul(x, x); p >>= 1; } return ret; } matrix modpow(const matrix &a, long long p, long long mod) { matrix ret = eye(a.size()); matrix x = a; while (p) { if (p & 1) ret = modmul(ret, x, mod); x = modmul(x, x, mod); p >>= 1; } return ret; } long long solve(long long a, long long b, long long n) { if (n == 0) return 2; if (n == 1) return 2 * a % MOD; matrix A = eye(2); A[0][0] = 2 * a % MOD; A[0][1] = ((b - a * a) % MOD + MOD) % MOD; A[1][0] = 1; A[1][1] = 0; A = modpow(A, n-1, MOD); return (2 * a * A[0][0] % MOD + 2 * A[0][1] % MOD) % MOD; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long a, b, n; cin >> a >> b >> n; cout << solve(a, b, n) << endl; return 0; }