;; -*- 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
;;;
;;; 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)))

(dotimes (idx (length *bit-reverse-table*))
  (let ((table *bit-reverse-table*)
        (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)))

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

;; Below is a somewhat slower but space efficient bit-reversal
;; (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))
;;   (if (<= size 8)
;;       (ash (mod (logand (* x #x0202020202) #x010884422010) 1023)
;;            (- size 8))
;;       (progn
;;         (setq x (logior (ash (logand x #xaaaaaaaaaaaaaaaa) -1)
;;                         (ash (logand x #x5555555555555555) 1)))
;;         (setq x (logior (ash (logand x #xcccccccccccccccc) -2)
;;                         (ash (logand x #x3333333333333333) 2)))
;;         (setq x (logior (ash (logand x #xf0f0f0f0f0f0f0f0) -4)
;;                         (ash (logand x #x0f0f0f0f0f0f0f0f) 4)))
;;         (setq x (logior (ash (logand x #xff00ff00ff00ff00) -8)
;;                         (ash (logand x #x00ff00ff00ff00ff) 8)))
;;         (setq x (logior (ash (logand x #xffff0000ffff0000) -16)
;;                         (ash (logand x #x0000ffff0000ffff) 16)))
;;         (ash (logior (ash x -32) (ldb (byte 64 0) (ash x 32)))
;;              (- size 64)))))

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

(eval-when (:compile-toplevel :load-toplevel :execute)
  (assert (= sb-vm:n-word-bits 64)))

(defun f2-echelon! (matrix)
  (declare #.OPT
           ((simple-array bit (100000 64)) matrix))
  (let* ((storage (array-storage-vector matrix))
         (rank 0))
    (declare (fixnum rank))
    (dotimes (target-col 64)
      (let* ((pivot-row (do ((i rank (+ 1 i)))
                            ((= i 100000) -1)
                          (unless (zerop (aref matrix i target-col))
                            (return i)))))
        (when (>= pivot-row 0)
          (let ((pivot-row/64 (floor (array-row-major-index matrix pivot-row 0) 64))
                (rank-row/64 (floor (array-row-major-index matrix rank 0) 64)))
            ;; swap rows
            (rotatef (sb-kernel:%vector-raw-bits storage rank-row/64)
                     (sb-kernel:%vector-raw-bits storage pivot-row/64))
            ;; eliminate the column
            (dotimes (i 100000)
              (unless (or (= i rank) (zerop (aref matrix i target-col)))
                (let ((base/64 (floor (array-row-major-index matrix i 0) 64)))
                  (setf (sb-kernel:%vector-raw-bits storage base/64)
                        (logxor (sb-kernel:%vector-raw-bits storage base/64)
                                (sb-kernel:%vector-raw-bits storage rank-row/64)))))))
          (incf rank))))
    (values matrix rank)))

(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 (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 64) :element-type 'bit))
         (storage (array-storage-vector mat)))
    (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 (sb-kernel:%vector-raw-bits storage i)
              (logreverse (logandc2 (aref as i) total-xor) 64)))
      (f2-echelon! mat)
      (let ((rxor 0))
        (declare (uint62 rxor))
        (dotimes (i n)
          (setf rxor (logxor rxor (logreverse (sb-kernel:%vector-raw-bits storage i) 64))))
        (println (+ (logior rxor total-xor) rxor))))))

#-swank (main)


Measured memory_bytes: 41572