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