F=[0,0,0] F[0],F[1],N=map(int,input().split()) F[2]=F[1]^F[0] print(F[N%3])