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 (Python):
N = int(input())
nums = list(map(int, input().split()))

bad = 0
for n in nums: bad ^= n

BASIS_LENGTH = 61

def reduce(num):
    total = 0
    power = 0
    for i in range(BASIS_LENGTH):
        if bad & (1 << i): continue
        total += ((num & (1 << i)) >> i) * pow(2, power)
        power += 1
    return total
    
def expand(num):
    total = 0
    power = 0
    for i in range(BASIS_LENGTH):
        if bad & (1 << i):
            continue
        total += ((num & (1 << power)) >> power) * pow(2, i)
        power += 1
    return total

BASIS = [0 for i in range(BASIS_LENGTH)]
numsPrime = [reduce(n) for n in nums]

f = lambda x : max(range(BASIS_LENGTH), key=lambda n: (x & (1 << n), n))

def insertVector(x):
    for i in range(BASIS_LENGTH -1, -1, -1):
        if x & (1 << i) == 0: continue
        if BASIS[i] == 0: BASIS[i] = x; return
        x ^= BASIS[i]
        
for x in numsPrime:
    insertVector(x)

def getSum():
    total = 0
    for el in reversed(BASIS):
        if el == 0: continue
        if el ^ total > total:
            total = el ^ total
    return total

print(2*expand(getSum()) + bad)

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(N, input_line):
    """Test Case
    >>> print_ans(3, "3 6 5")
    12
    >>> print_ans(4, "23 36 66 65")
    188
    >>> print_ans(20, "1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 611451291444233983 647509226592964607 251832107792119421 827811265410084479 864032478037725181")
    2012721721873704572
    """
    ar = np.array(input_line.split(), 'int64')
    X = np.bitwise_xor.reduce(ar)
    ar = np.hstack((ar, np.array([ 1 << i for i in range(60) if X&(1 << i)],'int64')))
    for k in range(60)[::-1]:
        b = 1 << k
        j = ar&b != 0
        i = np.where(j&(ar<2 * b))[0]
        if len(i):
            i = i[0]
            x = ar[i]
            ar[j] ^=x
            ar[i] = x
    r = np.bitwise_xor.reduce(ar)
    print(r+(r^X))

if __name__ == '__main__':
    N = int(input().rstrip())
    input_line = input().rstrip()
    print_ans(N, input_line)

Solution (Python):
import os
import os
import sys
from functools import reduce
from operator import xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
A = np.array(A, dtype=np.int64)


def dump(arr):
    for a in arr:
        print(np.binary_repr(a, 60))
    print()




odds = reduce(xor, A)
ans = odds


A &= ~odds



rank = 0
for d in reversed(range(60)):
    
    bits1 = (A >> d & 1).astype(bool)
    pos = bits1[rank:].argmax() + rank
    if not bits1[pos]:
        continue  
    if pos < rank:
        continue  

    
    pivot_row = A[pos]
    
    A[bits1] ^= pivot_row
    A[pos] = pivot_row
    
    A[pos], A[rank] = A[rank], A[pos]
    rank += 1

ans += reduce(xor, A) * 2
print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

not_important = 0
for a in A:
    not_important ^= a

for i in range(n):
    A[i] &= ~not_important

A.sort(reverse=True)
rank = 0
for digit in range(60, -1, -1):
    check_bit = 1 << digit

    for i in range(rank, n):
        if A[i] & check_bit:
            A[rank], A[i] = A[i], A[rank]
            break
    else:
        continue

    for i in range(n):
        if i == rank: continue
        if A[i] & check_bit:
            A[i] ^= A[rank]

    rank += 1

ans = 0
for i in range(rank):
    ans ^= A[i]

print(ans*2 + not_important)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

not_important = 0
for a in A:
    not_important ^= a

for i in range(n):
    A[i] &= ~not_important

A.sort()
rank = 0
for digit in range(60, -1, -1):
    check_bit = 1 << digit

    for i in range(rank, n):
        if A[i] & check_bit:
            A[rank], A[i] = A[i], A[rank]
            break
    else:
        continue

    for i in range(n):
        if i == rank: continue
        if A[i] & check_bit:
            A[i] ^= A[rank]

    rank += 1

ans = 0
for i in range(rank):
    ans ^= A[i]

print(ans*2 + not_important)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2, degrees
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)

INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = LI()
total_xor = 0
for i in range(n):
    total_xor ^= A[i]


for i in range(n):
    A[i] &= ~total_xor


r = 0
for i in range(60, -1, -1):
    for j in range(r, n):
        if (A[j] >> i) & 1:
            A[r], A[j] = A[j], A[r]
            break
    else:
        continue
    for j in range(n):
        if j == r:
            continue
        if (A[j] >> i) & 1:
            A[j] ^= A[r]
    r += 1


ret = 0
for i in range(n):
    ret ^= A[i]


print(ret * 2 + total_xor)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.append(0)
for i in range(n):
    a[n] ^= a[i]
    
    
for i in range(n):
    a[i] &= ~a[n]
r = 0
for i in range(60, -1, -1):
    for j in range(r, n):
        if (a[j] >> i) & 1:
            a[r], a[j] = a[j], a[r]
            break
    else:
        continue
        
    for j in range(n):
        if j == r:
            continue
        if (a[j]>>i) & 1:
            a[j] ^= a[r]
    r+=1
s = 0
for i in range(r):
    s ^= a[i]
    
print(s*2 + a[n])

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
 
s = 0
for i in range(N) :
    s ^= A[i]
    
for i in range(N) :
    A[i] &= ~s
 
r = 0
for i in range(60, -1, -1) :
    for j in range(r, N) :
        if (A[j] >> i) & 1 :
            A[r], A[j] = A[j], A[r]
            break
    else :
        continue
    
    for j in range(N) :
        if j == r :
            continue
        if (A[j] >> i) & 1 :
            A[j] ^= A[r]
    
    r += 1
    
ret = 0
for i in range(r) :
    ret ^= A[i]
    
print(ret * 2 + s)

Solution (Python):
from operator import xor
from functools import reduce

n = int(input())
a = list(map(int, input().split()))

sums = reduce(xor, a)

blu = set()
remain = set(range(n))

for i in range(61)[::-1]:
    if (sums >> i) & 1 == 0:
        di = -1
        for j in remain:
            if (a[j] >> i) & 1 == 1:
                di = j
                break
        if di != -1:
            blu.add(di)
            remain.remove(di)
            for j in range(n):
                if j != di and (a[j] >> i) & 1 == 1:
                    a[j] = a[j] ^ a[di]
bsum = 0
for i in blu:
    bsum = bsum ^ a[i]
print(bsum + (sums ^ bsum))

Solution (Python):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())), dtype = np.int64)

xor = np.bitwise_xor.reduce(A)


odd_digit = [1<<i for i in range(60) if xor&(1<<i)]


for i in odd_digit:
    A = A & (~i)

for i in range(60, - 1 , - 1):
    one_digit = (A & (1<<i) != 0)
    pivot_flag = np.where(one_digit &  (A < (1<<(i + 1))))[0]
    if len(pivot_flag) == 0:
        continue
    p = pivot_flag[0]
    pivot = A[p]
    A[one_digit] ^= pivot
    A[p] = pivot
    
res = sum(odd_digit) + 2*(np.bitwise_xor.reduce(A))
print(res)

Solution (Python):

N = int(input())
A = list(map(int, input().split()))







INT_BITS = 64




def maxSubarrayXOR(set,n):

	
	
	index = 0

	
	
	
	
	for i in range(INT_BITS-1,-1,-1):

		
		
		
		maxInd = index
		maxEle = -9223372036854775808
		for j in range(index,n):

			
			
			
			if ( (set[j] & (1 << i)) != 0
					and set[j] > maxEle ):

				maxEle = set[j]
				maxInd = j

		
		
		
		
		if (maxEle == -9223372036854775808):
			continue

		
		
		
		temp = set[index]
		set[index] = set[maxInd]
		set[maxInd] = temp

		
		
		maxInd = index

		
		
		
		for j in range(n):

			
			
			
			if (j != maxInd and
			(set[j] & (1 << i)) != 0):
				set[j] ^= set[maxInd]

		
		
		index += 1

	
	
	res = 0
	for i in range(n):
		res ^= set[i]
	return res

B = 0
for a in A:
	B ^= a

A2 = [a&(~B) for a in A]
d = maxSubarrayXOR(A2, N)

print(int(d) + int(B^d))

Solution (Python):
def GaussJordan_mod2(A):
    row=len(A)
    col=len(bin(max(A))[2::])
    rank=0
    for c in reversed(range(col)):
        pivot=-1
        for r in range(rank,row):
            if A[r]&(1<<c):
                pivot=r
                break
        if pivot==-1:
            continue
        A[pivot],A[rank]=A[rank],A[pivot]
        A_rank=A[rank]
        for r in range(row):
            if r!=rank and A[r]&(1<<c):
                A[r]^=A[rank]
        rank+=1
    return A

n=int(input())
A=list(map(int, input().split()))
d=len(bin(max(A)))-2
ans=0
xor_sum=0
for i in range(n):
    xor_sum^=A[i]
for i in range(d):
    bit=xor_sum&(1<<i)
    if bit:
        ans+=bit
        for i in range(n):
            A[i]-=bit&A[i]
J=GaussJordan_mod2(A)
xor=0
for i in range(n):
    xor^=J[i]
print(ans+2*xor)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

s = 0
for i in range(N) :
    s ^= A[i]
    
for i in range(N) :
    A[i] &= ~s

r = 0
for i in range(60, -1, -1) :
    for j in range(r, N) :
        if (A[j] >> i) & 1 :
            A[r], A[j] = A[j], A[r]
            break
    else :
        continue
    
    for j in range(N) :
        if j == r :
            continue
        if (A[j] >> i) & 1 :
            A[j] ^= A[r]
    
    r += 1
    
ret = 0
for i in range(r) :
    ret ^= A[i]
    
print(ret * 2 + s)

Solution (Python):
'''
Created on 2019/09/23

@author: oiwaiman
'''


import numpy as np

n = int(input())
aaa = np.fromiter(list(map(int, input().split())), np.int64)

all_x = np.bitwise_xor.reduce(aaa)

mask = ~all_x
bbb = aaa & mask

ans = 0
while True:
    a = bbb.max()
    if a == 0:
        break
    b = 1<<(int(a).bit_length() -1)
    bbb[bbb & b > 0] ^= a
    if ans & b == 0:
        ans ^= a


print (ans*2 + all_x)

Solution (Python):
n = int(input())
as_list = input().split(" ")
a_list = [ int(astr) for astr in as_list ]

x = 0

for a in a_list:
    x ^= a
for i in range(n):
    a_list[i] &= ~x
pos = 0

for b in range(59,-1,-1):

    for i in range(pos,n):
        a = a_list[i]
        if a & (1 << b):
            if i > pos:
                
                
                a_list[i] = a_list[pos]
                a_list[pos] = a

            for j in range(n):
                if j == pos:
                    continue
                if a_list[j] & (1 << b):
                    a_list[j] ^= a
            pos += 1
            break
    
y = 0

for a in a_list:
    y ^= a

print(x + 2 * y)

Solution (Python):

n = int(input())
a = [int(item) for item in input().split()]
aor = 0
axor = 0
for item in a:
    aor |= item
    axor ^= item

rank = 0
ans = 0
for bit in range(61):
    if axor & 1 << (60 - bit):
        ans += 1 << (60 - bit)
        continue
    found_in_bit = False
    for i in range(rank, n):
        if a[i] & 1 << (60 - bit):
            if not found_in_bit:
                a[rank], a[i] = a[i], a[rank]
                
                for j in range(rank):
                    if a[j] & 1 << (60 - bit):
                        a[j] ^= a[rank]
                found_in_bit = True
                rank += 1
            else:
                a[i] ^= a[rank-1]
        else:
            continue

ret = 0
for item in a:
    ret ^= item & ~axor
ans += ret * 2
print(ans)

Solution (Python):
import math

N = int(input())
A = list(map(int, input().split()))

def honya(n, L):
  k = 0
  E = len(L)
  for i in range(n - 1, -1, -1):
    for j in range(k, E):
      if (L[j] >> i) & 1:
        L[k], L[j] = L[j], L[k]
        break
    else:
      continue
    k += 1
    for j in range(k, E):
      if (L[j] >> i) & 1:
        L[j] ^= L[k - 1]
  return L

def nasu(n):
  return math.ceil(math.log(n + 1, 2))

A.sort(reverse = True)
M = nasu(A[0])
P = [1]
for i in range(M):
  P.append(P[-1] * 2)

D = [0] * M
for i in range(N):
  t = A[i]
  for j in range(M):
    if t & 1:
      D[j] += 1
    t >>= 1

ans = 0
for i in range(M - 1, -1, -1):
  if D[i] % 2 == 1:
    ans += P[i]
    for j in range(N):
      A[j] &= ~(1 << i)

L = honya(M, A)
t = 0
for i in range(N):
  if L[i] == 0: break
  if (t & (1 << (nasu(L[i]) - 1))) == 0:
    t ^= L[i]

for i in  range(M - 1, -1, -1):
  if (t >> i) & 1:
    ans += P[i] * 2
    
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
 
N=int(input())
A=list(map(int,input().split()))
 
XOR=0
for a in A:
    XOR^=a
 
for i in range(N):
    A[i] &=~XOR
    
USED=[0]*N
 
for bi in range(60,-1,-1):
    for i in range(N):
        if USED[i]==0 and A[i] & (1<<bi)!=0:
            USED[i]=1
            useind=i
            break
    else:
        continue
 
    for i in range(N):
        if i==useind:
            continue
        if A[i] & (1<<bi)!=0:
            A[i]^=A[useind]
            
ANS=0
for a in A:
    ANS^=a
 
print(2*ANS+XOR)

Solution (Python):
import sys
input = sys.stdin.readline
 
N=int(input())
A=list(map(int,input().split()))
 
XOR=0
for a in A:
    XOR^=a
 
for i in range(N):
    A[i] &=~XOR
    
USED=[0]*N
 
for bi in range(60,-1,-1):
    for i in range(N):
        if USED[i]==0 and A[i] & (1<<bi)!=0:
            USED[i]=1
            useind=i
            break
    else:
        continue
 
    for i in range(N):
        if i==useind:
            continue
        if A[i] & (1<<bi)!=0:
            A[i]^=A[useind]
            
ANS=0
for a in A:
    ANS^=a
 
print(2*ANS+XOR)

Solution (Python):


import math
import os
import sys


DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, A):
    allxor = 0
    for a in A:
        allxor ^= a

    while len(A) < 61:
        A.append(0)
    M = len(A)

    row = 0
    ans = 0
    for bi in range(61, -1, -1):
        b = 1 << bi
        if b & allxor:
            ans |= b
            continue

        if not (A[row] & b):
            j = -1
            for i in range(row + 1, M):
                if A[i] & b:
                    j = i
                    break
            if j == -1:
                continue

            A[row], A[j] = A[j], A[row]

        assert A[row] & b
        if not (ans & b):
            ans ^= A[row]

        for i in range(row + 1, M):
            if A[i] & b:
                A[i] ^= A[row]
            assert not (A[i] & b)

        row += 1

    return ans + (ans ^ allxor)


def main():
    N = int(inp())
    A = [int(e) for e in inp().split()]
    print(solve(N, A))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    xor=0
    max_digit=0
    for a in A:
        xor^=a
        max_digit=max(max_digit,a.bit_length())
    
    for i in range(n): A[i]&=(~xor)
    
    r=0 
    for d in reversed(range(max_digit)): 
        for i in range(r,n):
            if A[i]&(1<<d): 
                for j in range(i+1,n): 
                    if A[j]&(1<<d): A[j]^=A[i]
                A[i],A[r]=A[r],A[i] 
                r+=1
                break
    
    x=0
    for i in range(r):
        d=A[i].bit_length()
        if not x&(1<<(d-1)):
            x^=A[i]
    print(xor+2*x)
resolve()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    s = input()
    if s == "Sunny":
        print("Cloudy")
    elif s == "Cloudy":
        print("Rainy")
    else:
        print("Sunny")
    return


def B():
    s = S()
    for i in range(len(s)):
        if i%2:
            if s[i] not in ["L","U","D"]:
                print("No")
                return
        else:
            if s[i] not in ["R","U","D"]:
                print("No")
                return
    print("Yes")
    return


def C():
    n,k,q = LI()
    a = IR(q)
    f = [k-q]*(n)
    for i in range(q):
        ai = a[i]-1
        f[ai] += 1
    for i in f:
        if i <= 0:
            print("No")
        else:
            print("Yes")
    return


def D():
    n,m = LI()
    a = LI()
    q = []
    for i in range(n):
        heappush(q,-a[i])
    for i in range(m):
        x = heappop(q)
        x *= -1
        x >>= 1
        heappush(q,-x)
    print(-sum(q))
    return


def E():
    n = I()
    s = S()
    l = 0
    r = n
    M = 10**64+1
    b = 26
    alp = list("abcdefghijklmnopqrstuvwxyz")
    f = {}
    for i in alp:
        f[i] = ord(i)-ord("a")
    pb = [pow(b,i,M) for i in range(n+1)]
    while r-l > 1:
        m = (l+r)>>1
        d = defaultdict(lambda : float("inf"))
        hash = 0
        for i in s[:m]:
            hash *= b
            hash += f[i]
            hash %= M
        d[hash] = 0
        t = pb[m]
        for i in range(n-m):
            si = s[i]
            hash *= b
            hash -= t*f[si]
            hash += f[s[i+m]]
            hash %= M
            if d[hash]+m <= i+1:
                l = m
                break
            if i+1 < d[hash]:
                d[hash] = i+1
        else:
            r = m
    print(l)
    return


def F():
    """
    A := 赤く塗ったもののxor
    B := 青く塗ったもののxor
    S := 全体のxor

    <問題> A^Bの最大化

    A^B = S、およびA+B = A^B+(A&B)*2より
    A+B = S+(A&B)*2、Sは定数であるため、A&Bを最大化すればよい

    ここで、Sのiビット目がたっているときどのように分けてもA&Bは0となるため
    Ajからiビット目をすべて取り払う。これにより、どのような場合も全体のxorは0となり、
    常にA=Bが成り立つ。
    よってAの最大化を考えればよい。

    AはAjのxorの線形結合により生成される集合の要素である。
    ゆえにAjのxorの線形結合で作られる数のうち最大のものを解とすることができる。
    これは上位ビットから優先的にとるようにすれば生成が可能である。
    あとは基本行変形をおこない、解を求めやすい形にして階数の分だけ大きい順にAjをとれば解となる。
    
    """
    n = I()
    m = 60
    b = [1<<i for i in range(m)]
    a = LI()
    s = 0
    for i in a:
        s ^= i
    for i in range(m):
        if s&b[i]:
            for j in range(n):
                if a[j]&b[i]:
                    a[j] -= b[i]
    k = 0
    for j in range(m):
        bj = b[-j-1]
        for i in range(k,n):
            if a[i]&bj:
                break
        else:
            continue
        a[i],a[k] = a[k],a[i]
        for i in range(n):
            if i == k:
                continue
            if a[i]&bj:
                a[i] ^= a[k]

        k += 1
        if k == n:
            break
    ans = 0
    for i in range(k):
        ans ^= a[i]

    print(s+2*ans)
    return


if __name__ == "__main__":
    F()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    s = input()
    if s == "Sunny":
        print("Cloudy")
    elif s == "Cloudy":
        print("Rainy")
    else:
        print("Sunny")
    return


def B():
    s = S()
    for i in range(len(s)):
        if i%2:
            if s[i] not in ["L","U","D"]:
                print("No")
                return
        else:
            if s[i] not in ["R","U","D"]:
                print("No")
                return
    print("Yes")
    return


def C():
    n,k,q = LI()
    a = IR(q)
    f = [k-q]*(n)
    for i in range(q):
        ai = a[i]-1
        f[ai] += 1
    for i in f:
        if i <= 0:
            print("No")
        else:
            print("Yes")
    return


def D():
    n,m = LI()
    a = LI()
    q = []
    for i in range(n):
        heappush(q,-a[i])
    for i in range(m):
        x = heappop(q)
        x *= -1
        x >>= 1
        heappush(q,-x)
    print(-sum(q))
    return


def E():
    n = I()
    s = S()
    l = 0
    r = n
    M = 10**64+1
    b = 26
    alp = list("abcdefghijklmnopqrstuvwxyz")
    f = {}
    for i in alp:
        f[i] = ord(i)-ord("a")
    pb = [pow(b,i,M) for i in range(n+1)]
    while r-l > 1:
        m = (l+r)>>1
        d = defaultdict(lambda : float("inf"))
        hash = 0
        for i in s[:m]:
            hash *= b
            hash += f[i]
            hash %= M
        d[hash] = 0
        t = pb[m]
        for i in range(n-m):
            si = s[i]
            hash *= b
            hash -= t*f[si]
            hash += f[s[i+m]]
            hash %= M
            if d[hash]+m <= i+1:
                l = m
                break
            if i+1 < d[hash]:
                d[hash] = i+1
        else:
            r = m
    print(l)
    return


def F():
    n = I()
    m = 60
    b = [1<<i for i in range(m)]
    a = LI()
    s = 0
    for i in a:
        s ^= i
    for i in range(m):
        if s&b[i]:
            for j in range(n):
                if a[j]&b[i]:
                    a[j] -= b[i]
    k = 0
    for j in range(m):
        bj = b[-j-1]
        for i in range(k,n):
            if a[i]&bj:
                break
        else:
            continue
        a[i],a[k] = a[k],a[i]
        for i in range(n):
            if i == k:
                continue
            if a[i]&bj:
                a[i] ^= a[k]

        k += 1
        if k == n:
            break
    ans = 0
    for i in range(k):
        ans ^= a[i]
    print(s+2*ans)
    return


if __name__ == "__main__":
    F()

Solution (Python):
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))

XOR=0
for a in A:
    XOR^=a

for i in range(N):
    A[i] &=~XOR
    
USED=[0]*N

for bi in range(60,-1,-1):
    for i in range(N):
        if USED[i]==0 and A[i] & (1<<bi)!=0:
            USED[i]=1
            useind=i
            break
    else:
        continue

    for i in range(N):
        if i==useind:
            continue
        if A[i] & (1<<bi)!=0:
            A[i]^=A[useind]
            
ANS=0
for a in A:
    ANS^=a

print(2*ANS+XOR)

Solution (Python):
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))

XOR=0
for a in A:
    XOR^=a

for i in range(N):
    A[i] &=~XOR
    
USED=[0]*N

for bi in range(60,-1,-1):
    for i in range(N):
        if USED[i]==0 and A[i] & (1<<bi)!=0:
            USED[i]=1
            useind=i
            break
    else:
        continue

    for i in range(N):
        if i==useind:
            continue
        if A[i] & (1<<bi)!=0:
            A[i]^=A[useind]
            
ANS=0
for a in A:
    ANS^=a

print(2*ANS+XOR)

Solution (Python):
def xor_gauss_jordan(A):
    """掃き出し法でジョルダン標準形を求める"""
    cnt_row = len(A)
    cnt_col = len(bin(max(A))[2::])

    rank = 0
    for col in range(cnt_col):
        
        pivot = -1
        for row in range(rank, cnt_row):
            if A[row] & 2**(cnt_col - col - 1):
                pivot = row
                break

        
        if pivot == -1:
            continue

        
        A[pivot], A[rank] = A[rank], A[pivot]

        
        A_rank = A[rank]
        for row in range(cnt_row):
            if row != rank and A[row] & 2**(cnt_col - col - 1):
                A[row] ^= A[rank]
        rank += 1

    return A


n = int(input())
a = list(map(int, input().split()))




max_a = max(a)
max_a = bin(max_a)[2::]
len_max_a = len(max_a)




ans = 0
xor_sum = 0
for i in range(n):
    xor_sum ^= a[i]
for i in range(len_max_a):
    mask = 2**i
    tmp = mask & xor_sum
    if tmp:
        ans += tmp
        for i in range(n):
            a[i] -= tmp & a[i]


a = xor_gauss_jordan(a)

tmp = 0
for i in range(n):
    tmp ^= a[i]
print(ans + 2*tmp)

Solution (Python):
import numpy as np

n = int(input())
aaa = np.fromiter(map(int, input().split()), np.int64)

all_x = np.bitwise_xor.reduce(aaa)
mask = ~all_x
bbb = aaa & mask

ans = 0
while True:
    a = bbb.max()
    if a == 0:
        break
    b = 1 << (int(a).bit_length() - 1)
    bbb[bbb & b > 0] ^= a
    if ans & b == 0:
        ans ^= a

print(2 * ans + all_x)

Solution (Python):
import numpy as np

n = int(input())
aaa = np.fromiter(map(int, input().split()), np.int64)

all_x = np.bitwise_xor.reduce(aaa)
mask = ~all_x
bbb = aaa & mask

ans = 0
while any(bbb):
    a = bbb.max()
    b = 1 << (int(a).bit_length() - 1)
    bbb[bbb & b > 0] ^= a
    if ans & b == 0:
        ans ^= a

print(2 * ans + all_x)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    s = 0
    
    for a in aa:
        s ^= a
    

    
    for i in range(n):
        
        aa[i] &= ~s
        

    
    rnk = 0  
    for k in range(60, -1, -1):
        
        mask = 1 << k
        for i in range(rnk, n):
            if mask & aa[i]:
                aa[i], aa[rnk] = aa[rnk], aa[i]
                break
        else:
            continue
        
        for i in range(n):
            if i == rnk: continue
            if aa[i] & mask:
                aa[i] ^= aa[rnk]
        rnk += 1

    
    red = 0
    for i in range(rnk):
        red ^= aa[i]
    blue = s ^ red
    
    print(s + 2 * (red & blue))

main()

Solution (Python):
from functools import reduce

MAX_DIGIT = 60

N = int(input())
A = list(map(int, input().split()))

xorsum = reduce(lambda x, y: x ^ y, A)

A = [xor & ~xorsum for xor in A]

rank = 0
for digit in range(59, -1, -1):
    if (xorsum >> (MAX_DIGIT - digit - 1)) & 1 == 1:
        continue

    if rank >= N:
        break
    for j in range(rank, N):
        if A[j] & (1 << digit):
            break

    if j == N:
        continue

    if j > rank:
        A[rank] ^= A[j]

    for j in range(rank + 1, N):
        A[j] = min(A[j], A[j] ^ A[rank])

    rank += 1

x = 0
for i in range(N):
    x = max(x, x ^ A[i])

print(x * 2 + xorsum)

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



N = I()
A = III()

xor = 0
for i in range(N):
    xor ^= A[i]

for i in range(N):
    A[i] &= ~xor

max_digit = len(format(max(A), 'b'))
rank = 0
for col in range(max_digit)[::-1]:
    pivot = -1
    for row in range(rank,N):
        if A[row]>>col & 1:
            pivot = row
            break
    if pivot == -1: 
        continue
    A[pivot],A[rank] = A[rank],A[pivot]
    for row in range(rank+1,N):
        if A[row]>>col & 1:
            A[row] ^= A[rank]
    rank += 1

val = 0
for i in range(N):
    val = max(val,val^A[i])

print(2*val + xor)

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    x = 0
    for a in A:
        x ^= a

    idx = 0
    for i in range(59, -1, -1):
        if x >> i & 1 == 0:
            for j, a in enumerate(A[idx:], idx):
                if a >> i & 1:
                    break
            else:
                continue
            A[idx], A[j] = A[j], A[idx]
            for j in range(N):
                if j != idx and A[j] >> i & 1:
                    A[j] ^= a
            idx += 1

    
    

    s = 0
    for a in A:
        s ^= a
    

    for i in range(60):
        if x >> i & 1 == 1 and s >> i & 1:
            s ^= 1 << i

    
    print(x + (s << 1))

Solution (Python):
from numpy import *
f=bitwise_xor.reduce
N=int(input())
A=array(input().split(),int64)
X=f(A)
A=hstack((A,array([1<<i for i in range(60)if X&(1<<i)],int64)))
for k in range(60)[::-1]:
  b=1<<k
  j=A&b!=0
  i=where(j&(A<2*b))[0]
  if len(i):i=i[0];x=A[i];A[j]^=x;A[i]=x
r=f(A)
print(r+(r^X))

Solution (Python):
import numpy as np

N = int(input())
A = np.array(input().split(),dtype=np.int64)

xor = np.bitwise_xor.reduce(A)
A = np.concatenate([np.array([1<<i for i in range(60) if xor&(1<<i)],np.int64),A])

for k in range(60,-1,-1):
    bit = 1<<k
    one = (A&bit != 0)
    i = np.where(one & (A < (1<<(k+1))))[0]
    if len(i) == 0:
        continue
    i = i[0]
    x = A[i]
    A[one] ^= x
    A[i] = x

red = np.bitwise_xor.reduce(A)
blue = red^xor
answer = red + blue
print(answer)