Problem:
Score: 600 points

Problem Statement

We have N non-negative integers: A_1, A_2, ..., A_N.

Consider painting at least one and at most N-1 integers among them in red, and painting the rest in blue.

Let the beauty of the painting be the \mbox{XOR} of the integers painted in red, plus the \mbox{XOR} of the integers painted in blue.

Find the maximum possible beauty of the painting.

What is \mbox{XOR}?

The bitwise \mbox{XOR} x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non-negative integers x_1, x_2, \ldots, x_n is defined as follows:

When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.

For example, 3 \oplus 5 = 6.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

0 \leq A_i < 2^{60}\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible beauty of the painting.

Sample Input 1

3
3 6 5

Sample Output 1

12

If we paint 3, 6, 5 in blue, red, blue, respectively, the beauty will be (6) + (3 \oplus 5) = 12.

There is no way to paint the integers resulting in greater beauty than 12, so the answer is 12.

Sample Input 2

4
23 36 66 65

Sample Output 2

188

Sample Input 3

20
1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 611451291444233983 647509226592964607 251832107792119421 827811265410084479 864032478037725181

Sample Output 3

2012721721873704572

A_i and the answer may not fit into a 32-bit integer type.

Solution in Common Lisp (SBCL 1.1.14) (judge verdict: Wrong Answer)

;; -*- 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
;;;
;;; 1-dimensional binary indexed tree on arbitrary commutative monoid
;;;

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

(PROGN
 (DEFUN BITREE-UPDATE! (BITREE INDEX DELTA)
   "Destructively increments the vector: vector[INDEX] = vector[INDEX] +
DELTA"
   (declare #.OPT
            ((simple-array uint32 (*)) bitree)
            (int32 delta))
   (LET ((LEN (LENGTH BITREE)))
     (DO ((I INDEX (LOGIOR I (+ I 1))))
         ((>= I LEN) BITREE)
       (DECLARE ((INTEGER 0 4611686018427387903) I))
       (SETF (AREF BITREE I) (FUNCALL #'+ (AREF BITREE I) DELTA)))))
 (DEFUN BITREE-BISECT-LEFT (BITREE VALUE)
   "Returns the smallest index that satisfies VECTOR[0]+ ... +
VECTOR[index] >= VALUE. Returns the length of VECTOR if VECTOR[0]+
... +VECTOR[length-1] < VALUE."
   (DECLARE #.OPT
            ((simple-array uint32 (*)) BITREE)
            (uint32 value))
   (IF (NOT (FUNCALL #'< 0 VALUE))
       0
       (LET ((LEN (LENGTH BITREE)) (INDEX+1 0) (CUMUL 0))
         (DECLARE ((INTEGER 0 4611686018427387903) INDEX+1)
                  (TYPE UINT32 CUMUL))
         (DO ((DELTA (ASH 1 (- (INTEGER-LENGTH LEN) 1)) (ASH DELTA -1)))
             ((ZEROP DELTA) INDEX+1)
           (DECLARE ((INTEGER 0 4611686018427387903) DELTA))
           (LET ((NEXT-INDEX (+ INDEX+1 DELTA -1)))
             (WHEN (< NEXT-INDEX LEN)
               (LET ((NEXT-CUMUL (FUNCALL #'+ CUMUL (AREF BITREE NEXT-INDEX))))
                 (DECLARE (TYPE UINT32 NEXT-CUMUL))
                 (WHEN (FUNCALL #'< NEXT-CUMUL VALUE)
                   (SETF CUMUL NEXT-CUMUL)
                   (INCF INDEX+1 DELTA))))))))))

(defconstant +time-limit+ 1.8d0)

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (as (make-array n :element-type 'uint62)))
    (declare (uint32 n))
    (dotimes (i n)
      (setf (aref as i) (read-fixnum)))
    (let ((rxor (aref as 0))
          (bxor (aref as 1))
          (rcount 1)
          (bcount 1)
          (rdp (make-array 100000 :element-type 'uint32))
          (bdp (make-array 100000 :element-type 'uint32))
          (res 0)
          (max-temp (float (the uint62 (sb-int:power-of-two-ceiling (reduce #'max as))) 1d0)))
      (declare (uint62 rxor bxor res)
               (uint32 rcount bcount)
               (double-float max-temp))
      (bitree-update! rdp 0 1)
      (bitree-update! bdp 1 1)
      (loop for i from 2 below n
            do (if (>= (logxor rxor (aref as i))
                       (logxor bxor (aref as i)))
                   (progn
                     (bitree-update! rdp i 1)
                     (incf rcount)
                     (setq rxor (logxor rxor (aref as i))))
                   (progn
                     (bitree-update! bdp i 1)
                     (incf bcount)
                     (setq bxor (logxor bxor (aref as i))))))
      (sb-int:with-progressive-timeout (get-remaining-time :seconds +time-limit+)
        (dotimes (_ most-positive-fixnum)
          (let ((remaining-time (get-remaining-time)))
            (when (eq 0 (get-remaining-time))
              (println res)
              (return-from main))
            (let* ((ratio (* (the single-float remaining-time) #.(/ +time-limit+)))
                   (temp (+ 1d0 (* max-temp ratio))))
              (dotimes (_ 5000)
                (let ((r (random 3)))
                  (cond ((= 0 r)
                         (let* ((rpos (+ 1 (random rcount)))
                                (bpos (+ 1 (random bcount)))
                                (ridx (bitree-bisect-left rdp rpos))
                                (bidx (bitree-bisect-left bdp bpos))
                                (rval (aref as ridx))
                                (bval (aref as bidx))
                                (old-val (+ rxor bxor))
                                (new-rxor (logxor rxor rval bval))
                                (new-bxor (logxor bxor rval bval))
                                (new-val (+ new-rxor new-bxor))
                                (prob (exp (/ (- new-val old-val) temp))))
                           (when (< (random 1d0) prob)
                             (setq res (max res new-val))
                             (setq rxor new-rxor
                                   bxor new-bxor)
                             (bitree-update! rdp ridx -1)
                             (bitree-update! bdp bidx -1)
                             (bitree-update! rdp bidx 1)
                             (bitree-update! bdp ridx 1))))
                        ((= 1 r)
                         (when (> rcount 1)
                           (let* ((rpos (+ 1 (random rcount)))
                                  (ridx (bitree-bisect-left rdp rpos))
                                  (rval (aref as ridx))
                                  (old-val (+ rxor bxor))
                                  (new-rxor (logxor rxor rval))
                                  (new-bxor (logxor bxor rval))
                                  (new-val (+ new-rxor new-bxor))
                                  (prob (exp (/ (- new-val old-val) temp))))
                             (declare (uint32 ridx))
                             (when (< (random 1d0) prob)
                               (setq res (max res new-val))
                               (decf rcount)
                               (incf bcount)
                               (setq rxor new-rxor
                                     bxor new-bxor)
                               (bitree-update! rdp ridx -1)
                               (bitree-update! bdp ridx 1)))))
                        (t
                         (when (> bcount 1)
                           (let* ((bpos (+ 1 (random bcount)))
                                  (bidx (bitree-bisect-left bdp bpos))
                                  (bval (aref as bidx))
                                  (old-val (+ rxor bxor))
                                  (new-rxor (logxor rxor bval))
                                  (new-bxor (logxor bxor bval))
                                  (new-val (+ new-rxor new-bxor))
                                  (prob (exp (/ (- new-val old-val) temp))))
                             (declare (uint32 bidx))
                             (when (< (random 1d0) prob)
                               (setq res (max res new-val))
                               (decf bcount)
                               (incf rcount)
                               (setq rxor new-rxor
                                     bxor new-bxor)
                               (bitree-update! bdp bidx -1)
                               (bitree-update! rdp bidx 1)))))))))))))))

#-swank (main)