mod = 10 ** 9 + 7 def matrix_multiplication(a, b): n = len(a) res = [[0] * n for i in range(n)] for i in range(n): for k in range(n): for j in range(n): res[i][j] += a[i][k] * b[k][j] res[i][j] %= mod return res def matrix_pow(a, k): if k == 1: return a n = len(a) res = [[0] * n for i in range(n)] for i in range(n): res[i][i] = 1 while k: if k & 1: res = matrix_multiplication(res, a) a = matrix_multiplication(a, a) k >>= 1 return res A, B = map(int, input().split()) n = int(input()) M = [[A * 2, B - A ** 2], [1, 0]] M = matrix_pow(M, n - 1) print((M[0][0] * 2 * A + M[0][1] * 2) % mod)