;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (inline %merge))
(defun %merge (l mid r source-vec dest-vec predicate key)
  (declare ((mod #.array-total-size-limit) l mid r)
           (function predicate key))
  (loop with i = l
        with j = mid
        for idx from l
        when (= i mid)
        do (loop for j from j below r
                 for idx from idx
                 do (setf (aref dest-vec idx)
                          (aref source-vec j))
                 finally (return-from %merge t))
        when (= j r)
        do (loop for i from i below mid
                 for idx from idx
                 do (setf (aref dest-vec idx)
                          (aref source-vec i))
                 finally (return-from %merge t))
        do (if (funcall predicate
                        (funcall key (aref source-vec i))
                        (funcall key (aref source-vec j)))
               (setf (aref dest-vec idx) (aref source-vec i)
                     i (1+ i))
               (setf (aref dest-vec idx) (aref source-vec j)
                     j (1+ j)))))

(declaim (inline %insertion-sort!))
(defun %insertion-sort! (vec predicate l r key)
  (declare (function predicate key)
           ((mod #.array-total-size-limit) l r))
  (loop for end from (+ l 1) below r
        do (loop for i from end above l
                 while (funcall predicate
                                (funcall key (aref vec i))
                                (funcall key (aref vec (- i 1))))
                 do (rotatef (aref vec (- i 1)) (aref vec i)))
        finally (return vec)))

(declaim (inline merge-sort!))
(defun merge-sort! (vector predicate buffer &key (start 0) end (key #'identity))
  (declare ((simple-array uint32 (*)) vector buffer)
           (function predicate key))
  (let ((end (or end (length vector))))
    (declare ((mod #.array-total-size-limit) start end))
    (symbol-macrolet ((vec1 vector) (vec2 buffer))
      (labels ((recurse (l r merge-to-vec1-p)
                 (declare (optimize (safety 0))
                          ((mod #.array-total-size-limit) l r))
                 (cond ((= l r))
                       ((and (<= (- r l) 32) merge-to-vec1-p)
                        (%insertion-sort! vec1 predicate l r key))
                       (t (let ((mid (floor (+ l r) 2)))
                            (recurse l mid (not merge-to-vec1-p))
                            (recurse mid r (not merge-to-vec1-p))
                            (if merge-to-vec1-p
                                (%merge l mid r vec2 vec1 predicate key)
                                (%merge l mid r vec1 vec2 predicate key)))))))
        (recurse start end t)
        vector))))

(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  ;; (return-from read-fixnum 0)
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))
              (return (if minus (- result) result))))))))

(declaim (inline bisect-left))
(defun bisect-left (target value &key (start 0) end (predicate #'<) (key #'identity))
  "TARGET := vector | function
PREDICATE := strict order

Returns the smallest index (or input) i that fulfills TARGET[i] >= VALUE, where
'>=' is the complement of PREDICATE. TARGET must be monotonically non-decreasing with
respect to PREDICATE. This function returns END if VALUE exceeds TARGET[END-1]. Note
that the range [START, END) is half-open. END must be explicitly specified if
TARGET is function. KEY is applied to each element of TARGET before comparison."
  (declare (function key predicate)
           ((integer 0 #.most-positive-fixnum) start)
           ((or null (integer 0 #.most-positive-fixnum)) end))
  (macrolet
      ((body (accessor &optional declaration)
         `(cond ((assert (<= start end)))
                ((= start end) end)
                ((funcall predicate (funcall key (,accessor target (- end 1))) value)
                 end)
                (t (labels ((%bisect-left (l r)
                              ,@(list declaration)
                              (let ((mid (ash (+ l r) -1)))
                                (if (= mid l)
                                    (if (funcall predicate (funcall key (,accessor target l)) value)
                                        r
                                        l)
                                    (if (funcall predicate (funcall key (,accessor target mid)) value)
                                        (%bisect-left mid r)
                                        (%bisect-left l mid))))))
                     (%bisect-left start (- end 1)))))))
    (etypecase target
      (vector
       (let ((end (or end (length target))))
         (body aref (declare ((integer 0 #.most-positive-fixnum) l r)))))
      (function
       (assert end)
       (body funcall)))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (declare #.OPT
           (inline sort))
  (let* ((n (read))
         (as (make-array n :element-type 'uint32))
         (bs (make-array n :element-type 'uint32))
         (buffer (make-array n :element-type 'uint32))
         (res 0))
    (declare ((integer 0 200000) n)
             (uint32 res))
    (dotimes (i n) (setf (aref as i) (read-fixnum)))
    (dotimes (i n) (setf (aref bs i) (read-fixnum)))
    (dotimes (place 29)
      (let* ((number1 0)
             (power2+1 (expt 2 (+ place 1)))
             (power2 (expt 2 place))
             (bs-mod (merge-sort! (map '(simple-array uint32 (*))
                                       (lambda (x) (mod (the uint32 x) power2+1))
                                       bs)
                                  #'< buffer)))
        (declare (uint32 number1 power2+1 power2)
                 ((simple-array uint32 (*)) bs-mod buffer))
        (dotimes (i n)
          (let ((a-mod (mod (aref as i) power2+1)))
            (if (>= a-mod power2)
                (incf number1
                      (+ (bisect-left bs-mod (- power2+1 a-mod))
                         (- n
                            (bisect-left bs-mod (- (+ power2+1
                                                      power2)
                                                   a-mod)))))
                (incf number1
                      (- (bisect-left bs-mod (- power2+1 a-mod))
                         (bisect-left bs-mod (- power2 a-mod)))))))
        ;; (dbg place bs-mod number1)
        (when (oddp number1) (setf (ldb (byte 1 place) res) 1))))
    (println res)))

#-swank(main)


Measured memory_bytes: 76392