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

Solution (Python):
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
    for a in A: xor^=a
    
    for i in range(n): A[i]&=(~xor)
    
    r=0 
    for d in reversed(range(61)): 
        for i in range(r,n):
            if A[i]&(1<<d): 
                for j in range(i+1,n): 
                    if j==i: continue 
                    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):
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
    for a in A: xor^=a
    
    for i in range(n): A[i]&=(~xor)
    
    r=0 
    for d in reversed(range(61)): 
        for i in range(r,n):
            if A[i]&(1<<d): 
                for j in range(n): 
                    if j==i: continue 
                    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 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))

Solution (Python):
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))

Solution (Python):


class xorbasis:
    sz = 60
    table = [0] * sz

    def __init__(self):
        sz = self.sz
        for i in xrange(sz):
            self.table[i] = 0

    def add(self, x):
        sz = self.sz
        table = self.table
        
        for i in xrange(sz - 1, -1, -1):
            if x == 0: break
            
            if table[i] == 0: table[i] = x
            x = min(x, x ^ table[i])

    def maxi(self, s = 0):
        sz = self.sz
        table = self.table
        
        for i in xrange(sz - 1, -1, -1): s = max(s, s ^ table[i])

        return s

n = input()
a = map(int, raw_input().strip().split())

bits = [0] * 60

for i in xrange(n):
    for j in xrange(60):
        if (a[i] & (1 << j)): bits[j] += 1

ans = 0
for j in xrange(60):
    if (bits[j] & 1):
        xj = (1 << j)
        ans += xj
        for i in xrange(n):
            if (a[i] & xj): a[i] ^= xj

mat = xorbasis()

for i in xrange(n): mat.add(a[i])

x = mat.maxi()
ans += (2 * x)

print ans

Solution (Python):
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):



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

Solution (Python):
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)
 
"""
F_2 上の線形代数。基本変形で簡単な基底を得る。
"""
 
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)

Solution (Python):
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):
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)

"""
F_2 上の線形代数。基本変形で簡単な基底を得る。
"""

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)

Solution (Python):
rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())

def maxxorsum(A):
    N = len(A)
    low = 0
    for i in xrange(59, -1, -1):
        mi = low
        m = -(1 << 60)
        for j in range(low, N):
            if A[j] & (1 << i) and A[j] > m:
                mi = j
                m = A[j]
        if m == -(1 << 60):
            continue

        A[low], A[mi] = A[mi], A[low]
        mi = low
        for j in xrange(N):
            if j != mi and A[j] & (1 << i):
                A[j] ^= A[mi]
        low += 1

    ans = 0
    for x in A: ans ^= x
    return ans

def solve(N, A):
    base = 0
    for x in A:
        base ^= x

    baseneg = ~base
    for i, x in enumerate(A):
        A[i] &= baseneg
    return 2 * maxxorsum(A) + base

print solve(rri(), rrm())

Solution (Python):


  


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)