AtCoder Beginner Contest 141 - Xor Sum 3

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-----
3
3 6 5

-----Sample Output-----
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.

Difficulty: MEDIUM_HARD

Starter code:

Solutions:
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)


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)


import sys
from functools import reduce
from operator import xor
readline = sys.stdin.readline

def rev(x, k):
	res = 0
	for cnt in range(k):
		res = (res << 1) + (1 & x >> cnt)
	return res

class GE:

	def __init__(self, A, mod, M=0):
		self.N = len(A)
		if M:
			self.M = M
		else:
			self.M = len(A[0])
		self.mod = mod
		self.A = A[:]
		self.uptri = None
		self.A2 = None
		self.pivot = []
		self.R = None

	def ut(self):
		if self.mod != 2:
			if self.uptri is not None:
				return self.uptri
			self.uptri = self.A[:]
			c = 0
			for i in range(self.N):
				if i + c >= self.M:
					break
				while self.uptri[i][i + c] == 0:
					for j in range(i + 1, self.N):
						if self.uptri[j][i + c]:
							(self.uptri[i], self.uptri[j]) = (self.uptri[j], self.uptri[i])
							break
					else:
						c += 1
						if i + c == self.M:
							break
				else:
					self.pivot.append((i, i + c))
					t = pow(self.uptri[i][i + c], self.mod - 2, self.mod)
					for j in range(i + 1, self.N):
						tj = t * self.uptri[j][i + c]
						self.uptri[j][i + c:] = [(aj - tj * ai) % self.mod for (ai, aj) in zip(self.uptri[i][i + c:], self.uptri[j][i + c:])]
					continue
				break
			for (pi, pj) in self.pivot[::-1]:
				t = pow(self.uptri[pi][pj], self.mod - 2, self.mod)
				self.uptri[pi][pj:] = [ai * t % self.mod for ai in self.uptri[pi][pj:]]
				for i in range(pi - 1, -1, -1):
					ti = self.uptri[i][pj]
					self.uptri[i][pj:] = [(ai - api * ti) % self.mod for (ai, api) in zip(self.uptri[i][pj:], self.uptri[pi][pj:])]
			return self.uptri
		else:
			if self.A2 is not None:
				return self.A2
			self.A2 = self.A[:]
			c = 0
			for i in range(self.N):
				if i + c >= self.M:
					break
				while not self.A2[i] & 2 ** (i + c):
					for j in range(i + 1, self.N):
						if self.A2[j] & 2 ** (i + c):
							(self.A2[i], self.A2[j]) = (self.A2[j], self.A2[i])
							break
					else:
						c += 1
						if i + c == self.M:
							break
				else:
					self.pivot.append((i, i + c))
					for j in range(i + 1, self.N):
						if self.A2[j] & 2 ** (i + c):
							self.A2[j] ^= self.A2[i]
					continue
				break
			for (pi, pj) in self.pivot[::-1]:
				for i in range(pi - 1, -1, -1):
					if 2 ** pj & self.A2[i]:
						self.A2[i] ^= self.A2[pi]
			return self.A2

	def rank(self):
		if self.R is not None:
			return self.R
		self.ut()
		self.R = len(self.pivot)
		return self.R

	def solve(self):
		self.ut()
N = int(readline())
A = list(map(int, readline().split()))
M = reduce(xor, A)
ans = M
k = max(A).bit_length()
T = GE([rev(a & ~M, k) for a in A], 2, 60)
print(ans + 2 * reduce(xor, [rev(x, k) for x in T.ut()]))


n = int(input())
l = list(map(int, input().split()))
e = []
sx = 0
for i in l:
	sx ^= i
for i in l:
	i &= ~sx
	for j in e:
		i = min(i, i ^ j)
	if i:
		e.append(i)
t = 0
for i in e:
	t = max(t, t ^ i)
print((t ^ sx) + t)


n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in a:
	ans ^= i
k = ~ans
for i in range(n):
	a[i] &= k
rank = 0
for i in range(59, -1, -1):
	for j in range(rank, n):
		if a[j] >> i & 1:
			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])
	res = 0
	rank += 1
for i in a:
	res = max(res, res ^ i)
print(ans + 2 * res)


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(2 * ans + all_x)


N = int(input())
A = list(map(int, input().split()))
ans = 0
for a in A:
	ans ^= a
for i in range(N):
	A[i] &= ~ans

def gauss_jordan(bs):
	rank = 0
	pivot_cols = []
	for col in reversed(range(61)):
		pivot = -1
		for (i, row) in enumerate(bs[rank:]):
			if row & 1 << col:
				pivot = rank + i
				break
		if pivot < 0:
			continue
		pivot_cols.append(col)
		(bs[pivot], bs[rank]) = (bs[rank], bs[pivot])
		for (i, row) in enumerate(bs):
			if i != rank and row & 1 << col:
				bs[i] ^= bs[rank]
		rank += 1
	return (pivot_cols, bs)
(pivot_cols, bs) = gauss_jordan(A)
x = 0
for j in reversed(range(61)):
	nx = x | 1 << j
	b = nx
	for (i, c) in enumerate(pivot_cols):
		if b & 1 << c:
			b ^= bs[i]
	if b & nx == 0:
		x = nx
ans += x * 2
print(ans)


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)


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)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import numpy as np
N = int(input())
A = np.array([int(x) for x in 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
A = A[A != 0]
A.sort()
A = A[::-1]
if len(A) > 0:
	red = np.bitwise_xor.reduce(A)
else:
	red = 0
blue = red ^ xor
answer = red + blue
print(answer)


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


N = int(input())
A = list(map(int, input().split()))
res = 0
for x in A:
	res ^= x
for i in range(60):
	if res >> i & 1:
		for j in range(N):
			if A[j] >> i & 1:
				A[j] ^= 1 << i
start_point = 0
for i in range(60, -1, -1):
	X = 1 << i
	for j in range(start_point, N):
		if A[j] >> i & 1:
			(A[start_point], A[j]) = (A[j], A[start_point])
			for k in range(N):
				if A[k] >> i & 1 and k != start_point:
					A[k] ^= A[start_point]
			start_point += 1
			break
plus = 0
for x in A:
	plus ^= x
print(res + plus * 2)


N = int(input())
A = list(map(int, input().split()))
ans = 0
for a in A:
	ans ^= a
M = 2 ** 60 - 1
b = M ^ ans
for i in range(N):
	A[i] &= b
A.sort(reverse=True)
for i in range(min(60, N)):
	a = A[i]
	if a == 0:
		break
	l = len(bin(a)) - 3
	for j in range(N):
		if j == i:
			continue
		if A[j] // 2 ** l % 2 == 1:
			A[j] ^= a
		elif i < j:
			break
	A.sort(reverse=True)
s = 0
for a in A:
	s ^= a
ans += 2 * s
print(ans)


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)


def maxSubarrayXOR(lis, n, INT_BITS=60):
	idx = 0
	for i in range(INT_BITS - 1, -1, -1):
		Mele = -1
		bit_i = 1 << i
		for j in range(idx, n):
			if lis[j] & bit_i and lis[j] > Mele:
				(Midx, Mele) = (j, lis[j])
		if Mele < 0:
			continue
		(lis[Midx], lis[idx]) = (lis[idx], lis[Midx])
		for j in range(n):
			if j != idx and lis[j] & bit_i:
				lis[j] ^= lis[idx]
		idx += 1
	res = 0
	for x in lis:
		res ^= x
	return res
n = int(input())
a = list(map(int, input().split()))
t = 0
for x in a:
	t ^= x
b = [x ^ x & t for x in a]
print(t + maxSubarrayXOR(b, n) * 2)


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


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
s = 0
for a_i in a:
	s ^= a_i
c = [~s & a_i for a_i in a]
base = []
for c_i in c:
	for base_j in base:
		c_i = min(c_i, c_i ^ base_j)
	if c_i != 0:
		for j in range(len(base)):
			base[j] = min(base[j], base[j] ^ c_i)
		base.append(c_i)
		base.sort(reverse=True)
t = 0
for base_j in base:
	t ^= base_j
ans = s + t * 2
print(ans)


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
	for a in A:
		xor ^= a
	A = [a & ~xor for a in A]
	xor1 = 0
	for a in A:
		xor1 ^= a
	A.sort(reverse=1)
	now = 0
	for d in range(60, -1, -1):
		for p in range(now, n):
			if A[p] >> d:
				for i in range(n):
					if i == p:
						continue
					if A[i] >> d & 1:
						A[i] ^= A[p]
				(A[p], A[now]) = (A[now], A[p])
				now += 1
				break
	xor2 = 0
	for a in A:
		xor2 ^= a
	xor3 = xor1 ^ xor2
	print(xor + xor2 + xor3)
resolve()


from numpy import int64, bitwise_xor
(N, *A) = map(int, open(0).read().split())
A = int64(A)
x = bitwise_xor.reduce(A)
A &= ~x
res = 0
while any(A):
	ma = A.max()
	msb = 1 << int(ma).bit_length() - 1
	A[A & msb > 0] ^= ma
	res ^= ma * (not res & msb)
print(x + 2 * res)


import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
allxor = 0
for a in A:
	allxor ^= a
L = max(A).bit_length()
dp = [[] for _ in range(L + 1)]
for a in A:
	b = (a | allxor) ^ allxor
	if b != 0:
		dp[b.bit_length() - 1].append(b)
a1 = 0
for l in reversed(range(L)):
	if not dp[l]:
		continue
	c = dp[l].pop()
	if not a1 & 1 << l:
		a1 ^= c
	for p in dp[l]:
		b = c ^ p
		if b != 0:
			dp[b.bit_length() - 1].append(b)
ans = 2 * a1 + allxor
print(ans)


from heapq import *
N = int(input())
A = [int(a) for a in input().split()]
(x, t, s, i, h) = (0, 0, 0, 59, [])
for a in A:
	t ^= a
for a in A:
	heappush(h, -(a & ~t))
while h:
	a = -heappop(h)
	while i >= 0 and a >> i & 1 == 0:
		i -= 1
		x = 0
	if i < 0:
		break
	if x:
		heappush(h, -(a ^ x))
	else:
		x = a
		s = max(s, s ^ x)
print(s + (t ^ s))


def examA():
	W = {'Sunny': 'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}
	S = SI()
	ans = W[S]
	print(ans)
	return

def examB():
	R = {'R', 'U', 'D'}
	L = {'L', 'U', 'D'}
	S = SI()
	ans = 'Yes'
	for (i, s) in enumerate(S):
		if i % 2 == 0 and s in R:
			continue
		if i % 2 == 1 and s in L:
			continue
		ans = 'No'
		break
	print(ans)
	return

def examC():
	ans = 0
	print(ans)
	return

def examD():
	ans = 0
	print(ans)
	return

def examE():

	def z_algo(S):
		N = len(S)
		A = [0] * N
		i = 1
		j = 0
		A[0] = l = len(S)
		while i < l:
			while i + j < l and S[j] == S[i + j]:
				j += 1
			if not j:
				i += 1
				continue
			A[i] = j
			k = 1
			while l - i > k < j - A[k]:
				A[i + k] = A[k]
				k += 1
			i += k
			j -= k
		return A
	N = I()
	S = SI()
	ans = 0
	for i in range(N):
		Z = z_algo(S[i:])
		for (k, n) in enumerate(Z[1:]):
			cur = min(k + 1, n)
			ans = max(ans, cur)
	print(ans)
	return

def examF():

	def gauss_jordan(bs):
		rank = 0
		pivot_cols = []
		for col in reversed(range(61)):
			pivot = -1
			for (i, row) in enumerate(bs[rank:]):
				if row & 1 << col:
					pivot = rank + i
					break
			if pivot < 0:
				continue
			pivot_cols.append(col)
			(bs[pivot], bs[rank]) = (bs[rank], bs[pivot])
			for (i, row) in enumerate(bs):
				if i != rank and row & 1 << col:
					bs[i] ^= bs[rank]
			rank += 1
		return bs
	N = I()
	A = LI()
	bitlen = max(A).bit_length()
	even = {}
	for i in range(N):
		for j in range(bitlen):
			if A[i] & 1 << j:
				if j in even:
					even[j] ^= 1
				else:
					even[j] = 0
	A2 = [0] * N
	for i in range(N):
		for j in range(bitlen):
			if j in even and even[j]:
				A2[i] += A[i] & 1 << j
	ans = 0
	for (key, e) in even.items():
		if e == 0:
			ans += 1 << key
	L = gauss_jordan(A2)
	L.sort(reverse=True)
	now = L[0]
	for i in range(1, N):
		l = L[i]
		if l == 0:
			break
		n = l.bit_length() - 1
		if now & 1 << n > 0:
			continue
		now ^= l
	ans += now * 2
	print(ans)
	return
import traceback
import sys, copy, bisect, itertools, heapq, math, random
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LSI():
	return list(map(str, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10 ** 9 + 7
mod2 = 998244353
inf = 10 ** 18
_ep = 10 ** (-12)
alphabet = [chr(ord('a') + i) for i in range(26)]
examF()


n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
	cnt = 0
	for x in a:
		if x >> i & 1:
			cnt += 1
	if cnt % 2 == 1:
		ans += 1 << i
		for j in range(n):
			if a[j] >> i & 1:
				a[j] -= 1 << i
yet = 0
for r in range(59, -1, -1):
	stood = False
	for c in range(yet, n):
		if a[c] >> r & 1:
			if not stood:
				stood = True
				(a[yet], a[c]) = (a[c], a[yet])
				yet += 1
	if stood:
		for c in range(n):
			if c == yet - 1 or a[c] >> r & 1 == 0:
				continue
			a[c] ^= a[yet - 1]
tmp = 0
res = 0
for c in range(n):
	tmp ^= a[c]
	res = max(res, tmp)
print(ans + (res << 1))


import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
xorsm = 0
res = 0
for x in a:
	xorsm ^= x
for i in range(N):
	a[i] &= ~xorsm
ln = max(a).bit_length()
k = 0
for i in range(ln - 1, -1, -1):
	for j in range(k, N):
		if a[j] & 1 << i:
			(a[k], a[j]) = (a[j], a[k])
			break
	else:
		continue
	for j in range(N):
		if j == k:
			continue
		if a[j] & 1 << i:
			a[j] ^= a[k]
	k += 1
for i in range(k):
	res ^= a[i]
print(res * 2 + xorsm)


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)


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)


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)


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)


from numpy import *
N = int(input())
A = fromiter(map(int, input().split()), int64)
x = bitwise_xor.reduce(A)
A &= ~x
r = 0
while any(A):
	a = A.max()
	m = 1 << int(a).bit_length() - 1
	A[A & m > 0] ^= a
	r ^= a * (not r & m)
print(x + r + r)


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


import numpy as np

def solve(*args: str) -> str:
	n = int(args[0])
	A = np.array(args[1].split(), dtype=np.int64)
	n_bit = len(np.binary_repr(max(A)))
	xor = np.bitwise_xor.reduce(A)
	A &= ~xor
	for b in reversed(list(range(n_bit))):
		b_set = A & 1 << b != 0
		msb_args = np.where(b_set & (A < 1 << b + 1))[0]
		if len(msb_args):
			b_set[msb_args[0]] = False
			A[b_set] ^= A[msb_args[0]]
	ret = 2 * np.bitwise_xor.reduce(A) + xor
	return str(ret)

def __starting_point():
	print(solve(*open(0).read().splitlines()))
__starting_point()


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


from functools import reduce
from operator import xor
import numpy as np

def main():
	N = int(input())
	A = np.array(input().split(), np.int64)
	A_xor_all = np.bitwise_xor.reduce(A)
	mask = ~A_xor_all
	A_dash = A & mask
	ans = 0
	while True:
		_max = A_dash.max()
		if _max == 0:
			break
		most_left = int(_max).bit_length()
		b = 1 << most_left - 1
		A_dash[A_dash & b > 0] ^= _max
		if ans & b == 0:
			ans ^= _max
	print(2 * ans + A_xor_all)

def __starting_point():
	main()
__starting_point()


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)


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)


def get_basis(a):
	basis = []
	for e in a:
		for b in basis:
			e = min(e, e ^ b)
		if e:
			basis.append(e)
	return basis

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in a:
		ans ^= i
	k = ~ans
	for i in range(n):
		a[i] &= k
	basis = get_basis(a)
	res = 0
	for i in basis:
		res = max(res, res ^ i)
	print(ans + 2 * res)
solve()


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)


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


from sys import stdin
N = int(stdin.readline())
A = list(map(int, stdin.readline().split()))
allxor = 0
for i in range(N):
	allxor ^= A[i]
ans = 0
for i in range(60, -1, -1):
	ni = 2 ** i
	if ni & allxor > 0:
		ans += ni
		for j in range(N):
			if ni & A[j] > 0:
				A[j] ^= ni
able = [True] * N
for i in range(60, -1, -1):
	ni = 2 ** i
	ind = None
	for j in range(N):
		if able[j] and A[j] & ni > 0:
			ind = j
			able[j] = False
			break
	if ind != None:
		for j in range(N):
			if A[j] & ni > 0 and ind != j:
				A[j] ^= A[ind]
pl = 0
for i in range(N):
	pl ^= A[i]
print(ans + pl * 2)


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)


import sys
sys.setrecursionlimit(2147483647)
INF = float('inf')
MOD = 10 ** 9 + 7
input = sys.stdin.readline

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


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


import sys
input = sys.stdin.readline
import numpy as np

def print_ans(N, input_line):
	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))

def __starting_point():
	N = int(input().rstrip())
	input_line = input().rstrip()
	print_ans(N, input_line)
__starting_point()


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
x = 0
for a in A:
	x ^= a
now = 0
for i in range(59, -1, -1):
	if x >> i & 1:
		continue
	for j in range(now, n):
		if A[j] >> i & 1:
			(A[now], A[j]) = (A[j], A[now])
			for k in range(n):
				if k != now and A[k] >> i & 1:
					A[k] ^= A[now]
			now += 1
			break
b = 0
for a in A:
	b ^= a
ans = b + (x ^ b)
print(ans)


n = int(input())
a = list(map(int, input().split()))
sums = 0
for x in a:
	sums ^= x
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))


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


import sys
input = sys.stdin.readline

def I():
	return int(input())

def MI():
	return map(int, input().split())

def LI():
	return list(map(int, input().split()))

def main():
	mod = 10 ** 9 + 7
	N = I()
	A = LI()
	S = 0
	for i in range(N):
		S = S ^ A[i]
	M = 61
	delete = [0] * M
	ans = 0
	for i in range(M):
		if S >> i & 1:
			delete[i] = 1
			ans += 1 << i
			for j in range(N):
				if A[j] >> i & 1:
					A[j] -= 1 << i
	vec = []

	def dig_b(x):
		cnt = 0
		while x != 0:
			x = x // 2
			cnt += 1
		return cnt
	for i in range(N):
		now = A[i]
		d = dig_b(now)
		if vec == []:
			vec.append((now, d))
		else:
			for v in vec:
				if v[1] == d:
					now = now ^ v[0]
					d = dig_b(now)
			if now != 0:
				vec.append((now, d))
				vec.sort(reverse=True)
	temp = 0
	for v in vec:
		temp2 = temp ^ v[0]
		temp = max(temp, temp2)
	ans += temp * 2
	print(ans)
main()


import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())), dtype=np.int64)
a = np.bitwise_xor.reduce(A)
for i in range(60):
	bit = 1 << i
	if bit & a:
		A ^= A & bit
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
b = np.bitwise_xor.reduce(A)
a ^= b
print(a + b)


N = int(input())
xs = list(map(int, input().split()))
osum = 0
for x in xs:
	osum = osum ^ x
for i in range(N):
	xs[i] = xs[i] & ~osum
vs = set()
for i in range(60):
	i = 59 - i
	base = -1
	for (j, x) in enumerate(xs):
		if j in vs:
			continue
		if (x >> i) % 2:
			vs.add(j)
			base = j
			break
	if base < 0:
		continue
	for (j, x) in enumerate(xs):
		if j == base:
			continue
		if (x >> i) % 2:
			xs[j] = xs[j] ^ xs[base]
ksum = 0
for x in xs:
	ksum = ksum ^ x
print(osum + ksum * 2)


n = int(input())
A = [int(i) for i in input().split()]
suma = 0
for i in range(n):
	suma ^= A[i]
B = [~suma & me for me in A]
B.sort(reverse=True)
cnt = 0
for i in range(59, -1, -1):
	B.sort(reverse=True)
	if B[cnt] & 1 << i > 0:
		for q in range(cnt):
			if B[q] & 1 << i > 0:
				B[q] ^= B[cnt]
		for q in range(cnt + 1, n):
			if B[q] & 1 << i > 0:
				B[q] ^= B[cnt]
			else:
				break
		cnt += 1
ans = 0
B.sort(reverse=True)
for i in range(n):
	ans ^= B[i]
print(ans * 2 + suma)


import sys
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()
YesNo = lambda b: bool([print('Yes')] if b else print('No'))
YESNO = lambda b: bool([print('YES')] if b else print('NO'))
int1 = lambda x: int(x) - 1

def main():
	N = int(input())
	A = list(map(int, input().split()))
	A.sort(reverse=1)
	Xor = 0
	l = [-1] * 60
	for x in A:
		Xor ^= x
	Xornot = Xor ^ 2 ** A[0].bit_length() - 1
	for i in range(N):
		A[i] &= Xornot
	for x in A:
		if l[x.bit_length() - 1] == -1:
			l[x.bit_length() - 1] = x
	for i in range(len(l) - 1, -1, -1):
		if l[i] != -1:
			for j in range(len(l) - 1, i, -1):
				if l[j] != -1 and l[j] >> i & 1 == 1:
					l[j] ^= l[i]
	f = True
	while f:
		f = False
		for x in A:
			while x.bit_length() > 1:
				if l[x.bit_length() - 1] != -1:
					x ^= l[x.bit_length() - 1]
					if l[x.bit_length() - 1] == -1:
						l[x.bit_length() - 1] = x
						f = True
						break
				else:
					break
		for i in range(len(l) - 1, -1, -1):
			if l[i] != -1:
				for j in range(len(l) - 1, i, -1):
					if l[j] != -1 and l[j] >> i & 1 == 1:
						l[j] ^= l[i]
	tmp = 0
	for i in range(len(l) - 1, -1, -1):
		if l[i] != -1 and Xor >> i & 1 == 0:
			tmp ^= l[i]
	ans = tmp + (Xor ^ tmp)
	print(ans)
main()


INT_BITS = 61

def maxSubarrayXOR(set, n):
	index = 0
	for i in range(INT_BITS - 1, -1, -1):
		maxInd = index
		maxEle = -2147483648
		for j in range(index, n):
			if set[j] & 1 << i != 0 and set[j] > maxEle:
				maxEle = set[j]
				maxInd = j
		if maxEle == -2147483648:
			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[j] ^ set[maxInd]
		index = index + 1
	res = 0
	for i in range(n):
		res = res ^ set[i]
	return res
import sys
sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline
n = int(input())
a = [int(i) for i in readline().split()]
res = [0] * 60
for i in a:
	b = bin(i)[:1:-1]
	for (j, c) in enumerate(b):
		if c == '1':
			res[j] += 1
omask = 0
emask = 0
for (i, c) in enumerate(res):
	if c % 2:
		omask |= 1 << i
	elif c:
		emask |= 1 << i
for i in range(n):
	a[i] &= emask
res = maxSubarrayXOR(a, n)
print(omask + res * 2)


import sys
sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline
n = int(input())
a = [int(i) for i in readline().split()]
from functools import reduce
from operator import xor
NMAX = 62
omask = reduce(xor, a)
emask = (1 << NMAX) - 1
emask ^= omask
for i in range(n):
	a[i] &= emask
k = 0
for i in range(NMAX, -1, -1):
	for j in range(k, n):
		if a[j] & 1 << i:
			if j != k:
				(a[j], a[k]) = (a[k], a[j])
			for l in range(n):
				if l != k and a[l] & 1 << i:
					a[l] ^= a[k]
			k += 1
			break
print(omask + 2 * reduce(xor, a))


n = int(input())
a = list(map(int, input().split()))
p = [0] * 62

def insert(x):
	for i in range(60, -1, -1):
		if x >> i & 1:
			if not p[i]:
				p[i] = x
				break
			x ^= p[i]
all = 0
for x in a:
	all ^= x
for i in range(61):
	if all >> i & 1:
		for j in range(n):
			if a[j] >> i & 1:
				a[j] -= 1 << i
for x in a:
	insert(x)
ans = 0
for i in range(60, -1, -1):
	if p[i] ^ ans > ans:
		ans = p[i] ^ ans
print(ans + (ans ^ all))


N = int(input())
A = list(map(int, input().split()))
check = 0
for i in range(N):
	check ^= A[i]
t = 0
for i in range(60):
	if check >> i & 1 == 0:
		t += 2 ** i
for i in range(N):
	A[i] &= t
A.sort(reverse=True)
base = []
for i in range(N):
	for b in base:
		t = A[i] ^ b
		A[i] = min(A[i], t)
	if A[i] != 0:
		base.append(A[i])
new = 0
for b in base:
	t = new ^ b
	new = max(new, t)
print(check + new * 2)


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


def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	A = list(map(int, input().split()))
	cnt = [0] * 61
	for a in A:
		for j in range(61):
			if a >> j & 1:
				cnt[j] += 1
	ans = 0
	for j in range(61):
		if cnt[j] & 1:
			ans += 1 << j
	mask = (1 << 61) - 1 ^ ans
	for i in range(N):
		A[i] &= mask
	rnk = 0
	for j in range(60, -1, -1):
		for i in range(rnk, N):
			if A[i] >> j & 1:
				(A[rnk], A[i]) = (A[i], A[rnk])
				a = A[rnk]
				for ii in range(N):
					if ii == rnk:
						continue
					if A[ii] >> j & 1:
						A[ii] ^= a
				rnk += 1
				break
	ans2 = 0
	for i in range(rnk):
		ans2 ^= A[i]
	print(ans + ans2 * 2)
main()


n = int(input())
a = list(map(int, input().split()))
cnt = 0
ans = 0
st = set()
for j in range(60)[::-1]:
	num = 0
	for i in range(n):
		if a[i] & 1 << j:
			num += 1
	if num % 2:
		ans += 1 << j
		for i in range(n):
			if a[i] & 1 << j:
				a[i] ^= 1 << j
for j in range(60)[::-1]:
	for i in range(cnt, n):
		if a[i] & 1 << j:
			for k in range(n):
				if i != k and a[k] & 1 << j:
					a[k] ^= a[i]
			(a[i], a[cnt]) = (a[cnt], a[i])
			cnt += 1
			break
tmp = 0
for i in range(n):
	tmp ^= a[i]
print(ans + tmp * 2)


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