#Fibonacchi sequence import numpy as np a,b,N=map(int,input().split()) A = np.array([[a,b], [1, 0]],dtype="int64") mod =10 **9 + 7 def mat_f(X): if X == 0: return np.array([a, b], [0, 1]) elif X == 1: return A else: if X % 2 == 0: S = mat_f(X//2) S%=mod return np.dot(S, S) else: S = mat_f(X//2) S%=mod return np.dot(np.dot(S, S), A) mat = np.dot(mat_f(N), np.array([1, 0])) b=mat[1]%mod print(b)