import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) def matrix_multiplication_mod(A,B,p): l = len(A) m = len(B) n = len(B[0]) C = [[0]*n for _ in range(l)] for i in range(l): for j in range(n): C[i][j] = sum((A[i][k]*B[k][j]) % p for k in range(m)) % p return C def matrix_power_mod(A,n,p): l = len(A) C = [[0] * l for _ in range(l)] for i in range(l): C[i][i] = 1 while n > 0: if n % 2 == 1: C = matrix_multiplication_mod(C,A,p) A = matrix_multiplication_mod(A,A,p) n >>= 1 return C a,b = MI() n = I() mod = 10**9+7 if n == 0: print(2) exit() if n == 1: print((2*a) % mod) exit() A = [[2*a,-a**2+b],[1,0]] X = matrix_power_mod(A,n-1,mod) ans = X[0][0]*2*a+X[0][1]*2 ans %= mod print(ans)