;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (sb-int:defconstant-eqx OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0))
    #'equal)
  #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)
  #-swank (set-dispatch-macro-character
           #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS

(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)

;;;
;;; Bit-reversal operation
;;; Reference: https://stackoverflow.com/questions/746171/efficient-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c
;;;

(declaim ((simple-array (unsigned-byte 16) (65536)) *bit-reverse-table*))
(defparameter *bit-reverse-table*
  (make-array 65536 :element-type '(unsigned-byte 16)))

(defun initialize-bit-reverse-table ()
  (declare #.OPT)
  (let ((table *bit-reverse-table*))
    (dotimes (idx (length *bit-reverse-table*))
      (let ((x idx))
        (setq x (logior (ash (logand x #xaaaa) -1)
                        (ash (logand x #x5555) 1)))
        (setq x (logior (ash (logand x #xcccc) -2)
                        (ash (logand x #x3333) 2)))
        (setq x (logior (ash (logand x #xf0f0) -4)
                        (ash (logand x #x0f0f) 4)))
        (setq x (logior (ash x -8) (ldb (byte 16 0) (ash x 8))))
        (setf (aref table idx) x)))))

(initialize-bit-reverse-table)

(declaim (inline logreverse))
(defun logreverse (x size)
  "Returns the bit-reversal in the range [0, SIZE) of X."
  (declare ((unsigned-byte 64) x)
           ((integer 0 64) size))
  (let ((table *bit-reverse-table*))
    (ash (logior
          (ash (aref table (logand x #xffff)) 48)
          (ash (aref table (logand (ash x -16) #xffff)) 32)
          (ash (aref table (logand (ash x -32) #xffff)) 16)
          (aref table (logand (ash x -48) #xffff)))
         (- size 64))))

;;;
;;; Fast operations on GF(2)
;;;

(defun f2-echelon! (matrix)
  (declare #.OPT
           ((simple-array uint62 (100000)) matrix))
  (let* ((rank 0))
    (declare ((integer 0 #.most-positive-fixnum) rank))
    (dotimes (target-col 64)
      (let* ((pivot-row (do ((i rank (+ 1 i)))
                            ((= i 100000) -1)
                          (when (logbitp target-col (aref matrix i))
                            (return i)))))
        (when (>= pivot-row 0)
          ;; swap rows
          (rotatef (aref matrix rank)
                   (aref matrix pivot-row))
          ;; eliminate the column
          (dotimes (i 100000)
            (when (and (/= i rank) (logbitp target-col (aref matrix i)))
              (setf (aref matrix i)
                    (logxor (aref matrix i)
                            (aref matrix rank)))))
          (incf rank))))
    (values matrix rank)))

(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
                                  (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))))))))

(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)))

(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)
  (let* ((n (read))
         (as (make-array n :element-type 'uint62))
         (mat (make-array 100000 :element-type 'uint62)))
    (declare (uint32 n))
    (dotimes (i n)
      (setf (aref as i) (read-fixnum)))
    (let* ((total-xor (reduce #'logxor as)))
      (declare (uint62 total-xor))
      (dotimes (i n)
        (setf (aref mat i)
              (logreverse (logandc2 (aref as i) total-xor) 62)))
      (f2-echelon! mat)
      (let ((rxor 0))
        (declare (uint62 rxor))
        (dotimes (i n)
          (setf rxor (logxor rxor (logreverse (aref mat i) 62))))
        (println (+ (logior rxor total-xor) rxor))))))

#-swank (main)


Measured memory_bytes: 24676