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 f4=f2^f3 p [f2,f3,f4,f1][n%4+1] end