let lower_bound arr p =
  let rec f l r =
    if l >= r then r
    else
      let m = (l+r) / 2 in
      if p arr.(m) then f l m else f (m+1) r in
  f 0 (Array.length arr)

let () =
  let n = Scanf.scanf "%d" (fun n -> n) in
  let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x)) in
  let b = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x)) in
  let bm = Array.make n 0 in
  let rec nxt v i =
    if i >= n then nxt v (n-1) else if bm.(i) >= v then (if i = 0 then 0 else nxt v (i-1)) else i+1 in
  Array.fast_sort (-) a;
  Array.init 29 (fun i ->
    let m, mm = 1 lsl i, (2 lsl i) - 1 in
    b |> Array.iteri (fun i e -> bm.(i) <- e land mm);
    Array.fast_sort (-) bm;
    a |> Array.fold_left (fun (acc, (l0, r0, l1, r1)) x ->
      let xm = x land mm in
      let l0' = nxt (1 * m - xm) l0 in
      let r0' = nxt (2 * m - xm) r0 in
      let l1' = nxt (3 * m - xm) l1 in
      let r1' = nxt (4 * m - xm) r1 in
      (acc + r0'-l0' + r1'-l1', (l0', r0', l1', r1'))) (0, (n, n, n, n))
    |> fst |> (fun s -> (s land 1) lsl i))
  |> Array.fold_left (+) 0 |> Printf.printf "%d\n"