f0,f1,n=gets.split(" ").map!(&:to_i) if n==0 p f0 elsif n==1 p f1 else f2=f0^f1 f3=f1^f2 p [f1,f2,f3][(n-1)%3] end