m=10**9+7 A,B=map(int,input().split()) N=int(input()) def f(a,b,c,n): x,y=1,0 while n: if n&1: x,y=(x*a+y*c*b)%m,(x*c+y*a)%m a,c=(a*a+c*c*b)%m,a*c*2%m n=n>>1 return x print((f(A,B,1,N)+f(A,B,-1,N))%m)