import numpy as np MOD = pow(10,9)+7 a,b = map(int,input().split()) n = int(input()) A = np.array([[2*a, b - a**2], [1, 0]]) #print(A) MAX = 70 L = [A] for i in range(MAX): A = np.dot(A,A) A = np.mod(A, MOD) L.append(A) #print(L) X = np.array([[1, 0], [0, 1]]) for i in range(MAX): if (n-1>>i)&1 == 1: X = np.dot(X,L[i]) X = np.mod(X,MOD) ans = X[0,0]*2*a + X[0,1]*2 print(ans%MOD)