module Main
where

import           Control.Applicative
import           Control.Monad
import           Control.Monad.ST
import           Data.Array
import           Data.Bits
import           Data.List
import qualified Data.Vector         as V
import qualified Data.Vector.Mutable as VM

{-# 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
    --print $ (build 0 bs) `seq` 0
    print $ foldr1 xor $ zipWith ($) ((\k -> eachFigure k as) <$> [0..]) (build 0 bs)

-- keyより大きいところのインデックス
-- 広義単調増加関数であること
upperBoundImpl :: Word -> (Int, Int) -> (Int -> Word) -> Int
upperBoundImpl key (l, r) f =
    let mid = (l + r) `div` 2
        next = if f mid <= key then (mid, r) else (l, mid)
        in  if r - l <= 1 then r else
            upperBoundImpl key (next `seq` next) f

upperBound :: Word -> (Int, Int) -> (Int -> Word) -> Int
upperBound key (l, r) f = upperBoundImpl key (l - 1, r) f'
    where f' i = if i < l then minBound :: Word else f i

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 = V.fromList $ (`mod` bit (k + 1)) <$> sortedBs
        f a = xorOnFigure (length sortedBs) k $ (a +) . (v V.!)
    in  foldr1 xor $ map f $ (`mod` bit (k + 1)) <$> as

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

po = do
    res <- V.toList . msort . V.fromList . (map (read :: String -> Int) . words) <$> getLine
    putStrLn $ (show $ head res) ++ (concat $ (map (" " ++)) . (map show) $ tail res)
    print 0
