#xorf import math def tw(n): t=1.0 k=0 while t0: q=math.floor(n/t) # print (q) tt.append(q) # print (tt) q*=t t/=2 n-=q # print (n) k-=1 # print (k) while k>0: tt.append(0) # print (tt) k-=1 return tt def twe(li): en=0.0 t1=1 i=len(li)-1 while i>=0: en+=t1*li[i] t1*=2 i-=1 return en def xor(l0,l1): l2=[] for i in range(len(l1)): if l0[i]!=l1[i]: l2.append(1) else: l2.append(0) return l2 F0,F1,N=(float(i) for i in input().split()) if N==0.0: print(int(F0)) elif N==1.0: print(int(F1)) else: F0=tw(F0) F1=tw(F1) Di=len(F0)-len(F1) if Di>0: Dk=[0]*Di F1=Dk+F1 elif Di<0: Di*=-1 Dk=[0]*Di F0=Dk+F0 while N>1.0: F2=xor(F0,F1) F0=F1 F1=F2 N-=1 print(int(twe(F1)))