local ffi = require 'ffi' local C = ffi.C ffi.cdef [[ long atol(const char *str); int printf(const char *fmt, ...); ]] function split(s, p, f) local t = {} for e in s:gmatch(p) do table.insert(t, f(e)) end return unpack(t) end local zero, one = ffi.new("long", 0), ffi.new("long", 1) local two, three = one + one, one + one + one function ltob(n) if n == zero then return "0" end local s = "" while n > zero do s = s .. (n%two ~= zero and "1" or "0") n = n / two end return s end function lxor(n1, n2) local s1, s2 = ltob(n1), ltob(n2) local n3, i, p = ffi.new("long", 0), 1, ffi.new("long", 1) while true do local c1, c2 = s1:sub(i,i), s2:sub(i,i) if c1 == "" or c2 == "" then break end n3 = n3 + p * (c1 ~= c2 and one or zero) i, p = i + 1, p * two end (#s1 > #s2 and s1 or #s1 < #s2 and s2 or ""):sub(i):gsub(".", function (e) n3 = n3 + p * (e == "1" and one or zero) p = p * two end) return n3 end local f0, f1, n = split(io.stdin:read("*l"), "%d+", C.atol) local f2 = lxor(f0, f1) C.printf("%ld\n", n % three == zero and f0 or n % three == one and f1 or f2)