a,b,n=map(int,input().split()) if n<=1: print(n) exit() l=2 M=10**9+7 def seki(a,b): c=[[0]*l for i in range(l)] for i in range(l): for j in range(l): for k in range(l): c[i][j]+=a[i][k]*b[k][j] c[i][j]%=M return c A=[[a,b],[1,0]] B=[[1,0],[0,1]] n-=1 for i in range(30): if (n>>i)&1: B=seki(A,B) A=seki(A,A) print(B[0][0])