import Data.Bits zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c] zipWith' f (x:xs) (y:ys) = let z = f x y in z `seq` z : zipWith' f xs ys zipWith' _ _ _ = [] fib :: Int -> Int -> [Int] fib a b = a : b : zipWith' xor xs (tail xs) where xs = fib a b main = do [a, b, n] <- fmap (map read . words) getLine print $ fib a b !! (n `mod` 3)