def to2(num): bList = [] if num == 0: return [0] while num > 0: bList.append(num % 2) num = num // 2 return bList def to10(numList): r = 0 n = len(numList) for i in range(n): r = r + numList[i] * (2 ** i) return r def xorList(f0List, f1List, num): len0 = len(f0List) len1 = len(f1List) length = 0 if len0 > len1: length = len0 for i in range(len0 - len1): f1List.append(0) elif len1 > len0: length = len1 for i in range(len1 - len0): f0List.append(0) else: length = len0 rList = [] for i in range(length): if f0List[i] == 0 and f1List[i] == 0: rList.append(0) elif f0List[i] == 1 and f1List[i] == 0: if num % 3 == 1: rList.append(0) else: rList.append(1) elif f0List[i] == 0 and f1List[i] == 1: if num % 3 == 0: rList.append(0) else: rList.append(1) else: if num % 3 == 2: rList.append(0) else: rList.append(1) return rList f0, f1, n = map(int, input().split()) rbList = [] if n == 0: r = f0 elif n == 1: r = f1 else: f0b = to2(f0) f1b = to2(f1) rList = xorList(f0b, f1b, n) r = to10(rList) print(r)