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
input = sys.stdin.readline

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


"""
全体のxor=S
赤のxor=xとすれば
求値は x+(S^x)の最大値
きつい

上の桁から見て，
Sのi桁目が0の時，その桁が1のものを奇数ずつ割り振りたい．
Sのi桁目が1の時，どんな分け方しても関係ない

上の桁から埋めたいというのはxを最大化したいというのと似ている．
Sのi桁目が1のぶんは先に計算しておく,かつ，各A[i]のその桁を0にしておけば，xを最大化したいという問題に帰着するか

xorの最大化，難しい．基底ベクトルに分解して，上の桁から足していく？
"""
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()

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

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

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

Solution (Python):

"""

https://atcoder.jp/contests/abc141/tasks/abc141_f

=====答えを見た=====

奇数の桁は取り除いて0にしておく
後は適当に掃きだす

"""

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)

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

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

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

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

if __name__ == '__main__':
    examF()

"""

"""

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

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


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
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
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
basis=get_basis(a)
res=0
for i in basis:
    res=max(res,res^i)
print(ans+2*res)

Solution (Python):
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])
    rank+=1
res=0
for i in a:
    res=max(res,res^i)
print(ans+2*res)

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

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

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

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

Solution (Python):

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)

if __name__ == '__main__':
    main()

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

Solution (Python):
def maxSubarrayXOR(lis, n, INT_BITS = 60):
    idx = 0
    for i in range(INT_BITS-1,-1,-1):
        Midx = -1
        bit_i = 1 << i
        for j in range(idx, n):
            if lis[j] & bit_i:
                Midx = j
                break
        else: 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)

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

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


if __name__ == '__main__':
    main()

Solution (Python):
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 A.any():
    ma = A.max()
    msb = 1 << (int(ma).bit_length() - 1)

    A[(A & msb) > 0] ^= ma

    res ^= ma * (not res & msb)

print(x + 2 * res)

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

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):
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):
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
        else:
            if i < j:
                break
    A.sort(reverse=True)
s = 0
for a in A:
    s ^= a
ans += 2*s
print(ans)

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

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

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

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

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

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

Solution (Python):

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


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

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