{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
module Main
where

import           Control.Applicative
import           Control.Monad
import           Control.Monad.ST
import           Data.Array
import           Data.Bits
import qualified Data.ByteString.Char8       as BC
import           Data.List
import           Data.Maybe
import           Data.STRef
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

{-# INLINE bucketsort #-} -- 昇順ソート
bucketsort :: (Int, Int) -> [Int] -> [Int]
bucketsort dom = bucketsortBy id dom

{-# INLINE bucketsortBy #-} -- 昇順ソート
bucketsortBy :: (a -> Int) -> (Int, Int) -> [a] -> [a]
bucketsortBy getkey dom = concatMap reverse . filter (not . null)
    . elems . accumArray (flip (:)) [] dom . map (\x -> (getkey x, x))

{-# INLINE bucketsortDescBy #-} -- 降順ソート
bucketsortDescBy :: (a -> Int) -> (Int, Int) -> [a] -> [a]
bucketsortDescBy getkey dom = reverse . concat . filter (not . null)
    . elems . accumArray (flip (:)) [] dom . map (\x -> (getkey x, x))

marge :: Ord a => VM.STVector s a -> VM.STVector s a -> VM.STVector s a -> ST s ()
marge u v ret
  | VM.null u = VM.copy ret v
  | VM.null v = VM.copy ret u
  | otherwise = do
        x <- VM.read u 0
        y <- VM.read v 0
        if x > y then marge v u ret else do
            VM.write ret 0 x
            marge (VM.tail u) v (VM.tail ret)

testMarge :: V.Vector Int
testMarge = runST $ do
    x <- V.thaw $ V.fromList ([1, 4] :: [Int])
    y <- V.thaw $ V.fromList ([2, 3] :: [Int])
    res <- VM.new 4
    marge x y res
    V.freeze res

msort :: Ord a => V.Vector a -> V.Vector a
msort v = runST $ do
    v' <- V.thaw v
    work <- VM.new $ VM.length v'
    msort_ v' work
    V.unsafeFreeze v'

msort_ :: Ord a => VM.STVector s a -> VM.STVector s a -> ST s ()
msort_ v work
  | VM.length v <= 1 = return ()
  | otherwise        = do
        VM.copy lwork lv
        VM.copy rwork rv
        msort_ lwork lv
        msort_ rwork rv
        marge lwork rwork v
        where
            toHalf vm = VM.splitAt (VM.length vm `div` 2) vm
            (lv, rv) = toHalf v
            (lwork, rwork) = toHalf work


main :: IO ()
main = do
    n <- (read :: String -> Int) <$> getLine
    {-as <- map (read :: String -> Word) . words <$> getLine
    bs <- map (read :: String -> Word) . words <$> getLine-}
    as <- getWords
    bs <- getWords
    --print $ (build 0 bs) `seq` 0
    when (n < 50000) $ print $ foldr1 xor $ zipWith ($) ((\k -> eachFigure k as) <$> [0..]) (build 0 bs)

readWords :: BC.ByteString -> [Word]
readWords = map (fromIntegral . fst . fromJust . BC.readInt) . BC.words

getWords :: IO [Word]
getWords = readWords <$> BC.getLine

-- keyより大きいところのインデックス
-- 広義単調増加関数であること
upperBoundImpl :: Word -> (Int, Int) -> (Int -> Word) -> Int
{-upperBoundImpl key (al, ar) f = runST $ do
    l <- newSTRef al
    r <- newSTRef ar
    mid <- newSTRef 0
    let loop = do
            l' <- readSTRef l
            r' <- readSTRef r
            if r' - l' <= 1 then return r' else do
                writeSTRef mid $ shiftR (l' + r') 1
                mid' <- readSTRef mid
                if f mid' <= key
                then writeSTRef l mid'
                else writeSTRef r mid'
                loop
    loop-}
upperBoundImpl key (l, r) f =
    let mid = shiftR (l + r) 1
    in  if r - l <= 1 then r else
        if f mid <= key
            then upperBoundImpl key (mid, r) f
            else upperBoundImpl key (l, mid) f

upperBound :: Word -> (Int, Int) -> (Int -> Word) -> Int
upperBound key (l, r) = upperBoundImpl key (l - 1, r)

test :: IO()
test = print $ upperBound 1 (0, 5) $ ((listArray (0, 4) [1, 1, 1, 1, 1] :: Array Int Word) !)

xorOnFigure :: Int -> Int -> (Int -> Word) -> Word
xorOnFigure n k sorted =
    let notCarriers = upperBound (bit (k + 1) - 1) (0, n) sorted
        i = upperBound (bit k - 1) (0, notCarriers) sorted
        j = upperBound (bit (k + 1) + bit k - 1) (notCarriers, n) sorted
        cnt = (notCarriers - i) + (n - j)
    in  if odd cnt then bit k else 0

eachFigure :: Int -> [Word] -> [Word] -> Word
eachFigure k as sortedBs =
    let v = VU.fromList $ (.&. (bit (k + 1) - 1)) <$> sortedBs
        f a = xorOnFigure (length sortedBs) k $ (a +) . (VU.unsafeIndex v)
    in  foldr1 xor $ map f $ (.&. (bit (k + 1) - 1)) <$> as

build :: Int -> [Word] -> [[Word]]
build 29 _ = []
build k bs = sorted : build (k + 1) sorted
    where sorted = bucketsortBy (\w -> if testBit w k then 1 else 0) (0, 1) bs :: [Word]
