a, b, n = [ int(v) for v in input().split() ] path_mat = [ [a, b], [1, 0] ] mod = 10**9+7 def mat_mul(inmat1,inmat2,m): outmat = [ [ 0 for j in range(m) ] for i in range(m) ] for i in range(m): for j in range(m): for g in range(m): outmat[i][j] += inmat1[i][g] * inmat2[g][j] outmat[i][j] %= mod return outmat ans_mat = [ [ 1 if i == j else 0 for j in range(2) ] for i in range(2) ] while n != 0: if n % 2 == 1: ans_mat = mat_mul(ans_mat,path_mat,2) n = n // 2 path_mat = mat_mul(path_mat,path_mat,2) print(ans_mat[1][0])