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.



Sample input:
3
3 6 5


Sample output:
12

Submission status: Wrong Answer

Solution code:
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:
        #print(i,"!")
        for q in range(cnt):
            if B[q]&(1<<i)>1:
                B[q]^=B[cnt]
        for q in range(cnt+1,n):
            if B[q]&(1<<i)>1:
                B[q]^=B[cnt]
            else:
                break          
        cnt+=1

ans=0
B.sort(reverse=True)
for i in range(min(n,60)):
    ans^=B[i]

print(ans*2+suma)

Submission status: Wrong Answer

Solution code:
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:
        #print(i,"!")
        for q in range(cnt):
            if B[q]&(1<<i)>1:
                B[q]^=B[cnt]
        for q in range(cnt+1,n):
            if B[q]&(1<<i)>1:
                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)

Submission status: Wrong Answer

Solution code:
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 |= 1 << i
print(ans + (ans ^ all))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(sorted(map(int, input().split()), reverse=True))

a, b = 0, 0

for i in v:
    na = a^i
    nb = b^i
    if na-a == nb -b:
        if na > nb:
            a = na
        else:
            b = nb
    elif na-a > nb-b:
        a = na
    else:
        b = nb

print(a+b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
a = np.bitwise_xor.reduce(A)
A^=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
b = np.bitwise_xor.reduce(A)
a^=b
print(a+b)

Submission status: Wrong Answer

Solution code:
def f(arr) :
  arr.sort(reverse=True)
  left = 0
  right = 0
  
  for a in arr :
    put_left = left^a + right
    put_right = left + right^a
    if put_left > put_right:
      left = left^a
    else :
      right = right^a
  
  return left + right

input()
print(f([int(x) for x in input().split(' ')]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.append(0)
for i in range(n):
    a[n] ^= a[i]
    #全ての排他的論理和を求める。→興味があるのは、2進数で1が偶数個立ってる列。
    #ここでa[n]に奇数個しか1がないもの
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 (a[j] == a[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])

Submission status: Wrong Answer

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

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

def rec(A, R, B):# 初期値R = T, B = 0
    x = - 1
    score = R + B
    for i in range(len(A)):
        if score <= (R ^ A[i]) + (B ^ A[i]):
            score = (R ^ A[i]) + (B ^ A[i])
            x = i
    if x == - 1:
        return score
    R = R ^ A[x]
    B = B ^ A[x]
    A.pop(x)
    return rec(A, R, B)

print(rec(A, T, 0))

Submission status: Wrong Answer

Solution code:
'''
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 ^= b

print (ans*2 + all_x)

Submission status: Wrong Answer

Solution code:
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))

#################

import numpy as np

def GaussJordan(A, is_extended = False):
    rank = 0
    for col in range(len(A[0])):
        if (is_extended and col == len(A[0])-1):
            break
        pivot = -1
        for row in range(rank,len(A)):
            if A[row][col]:
                pivot = row
                break
        if pivot == -1: 
            continue
        A[[pivot,rank]] = A[[rank,pivot]]
        for row in range(len(A)):
            if (row != rank and A[row][col]):
                A[row] ^= A[rank]
        rank += 1
    return A

N = I()
A = III()

xor = 0
for i in range(N):
    xor ^= A[i]
xor = format(xor,'b').zfill(60)

digit = defaultdict(int)
use_digit = []
not_use_digit = []
for j in range(60)[::-1]:
    if xor[60-j-1] == '0':
        digit[j] = 1
        use_digit.append(j)
    else:
        not_use_digit.append(j)

a = []
for i in range(N):
    binary = format(A[i], 'b').zfill(60)
    x = []
    for j in range(60)[::-1]:
        if digit[j]:
            if binary[60-j-1] == '0':
                x.append(0)
            else:
                x.append(1)
    a.append(x)

a = np.array(a)

g = GaussJordan(a,False)

ans = 0
p = 0
for j in not_use_digit:
    ans += 2**j

result = []
for i in range(N):
    for j in range(len(use_digit)):
        if g[i][j]==1:
            result.append(i)
            break

s = np.zeros(len(use_digit))
for r in result:
    s = np.logical_xor(s, g[r])
for k in range(len(s)):
    ans += (s[k]+0)*2**(use_digit[k]+1)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
cnt=[0 for i in range(100)]
for i in l:
    j=0
    while(i>0):
        if((i&1)==1):
            cnt[j]+=1
        i//=2
        j+=1
now=1
res=0
for i in range(100):
    if (cnt[i]==0):
        pass
    elif (cnt[i]%2)==0:
        res+=now*2
    else:
        res+=now
    now*=2
print(res)

Submission status: Wrong Answer

Solution code:
import heapq
N = int(input())
A = list(map(int,input().split()))

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

for i in range(N):
    A[i] = (~ans)&A[i]
A = [-a for a in A]
heapq.heapify(A)

b = []
while len(A)>1:
    M = -heapq.heappop(A)
    if M == 0:
        break
    while True:
        m = -heapq.heappop(A)
        if len(bin(M))==len(bin(m)):
            m ^= M
            heapq.heappush(A,-m)
        else:
            break
    b.append(M)
if A and A[0] != 0:
    b.append(A[0])

b = b[::-1]
ans_ = 0
for i in range(len(b)):
    M = b[i]
    for j in range(i+1,len(b)):
        m = b[j]
        if len(bin(M))==len(bin(M&m)):
            b[j] ^= M
    ans_ ^= M

ans += ans_*2
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
N = int(input())
A = list(map(int,input().split()))

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

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

heapq.heapify(A)

b = []
while A:
    c = heapq.heappop(A)
    if c==0:
        continue
    A_ = []
    used = False
    for a in A:
        if len(bin(c))==len(bin(a&c)):
            a ^= c
            used = True
        heapq.heappush(A_,a)
    if used:
        heapq.heappush(A_,c)
    else:
        b.append(c)
    A = A_

ans_ = 0
for a in b:
    ans_ ^= a
ans += 2*ans_

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 60

if N <= 21:
    ans = 0
    for i in range(1<<N):
        R = 0
        B = 0
        for j in range(N):
            if i & (1<<j):
                R ^= A[j]
            else:
                B ^= A[j]
        ans = max(ans, R+B)
    print(ans)
else:
    for a in A:
        for i in range(60):
            if a & 1:
                X[i] += 1
            a >>= 1
    ans = 0
    for i in range(60):
        if X[i] & 1:
            ans += 1<<i
        elif X[i]:
            ans += 1<<i+1
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
x=a[-1]
y=0
for i in a[:-1]:y^=i
print(x+y)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 60

if N <= 22:
    ans = 0
    for i in range(1<<N):
        R = 0
        B = 0
        for j in range(N):
            if i & (1<<j):
                R ^= A[j]
            else:
                B ^= A[j]
        ans = max(ans, R+B)
    print(ans)
else:
    for a in A:
        for i in range(60):
            if a & 1:
                X[i] += 1
            a >>= 1
    ans = 0
    for i in range(60):
        if X[i] & 1:
            ans += 1<<i
        elif X[i]:
            ans += 1<<i+1
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
R,B = 0,0
A.sort(reverse=True)
R = 0
for i in range(N):
    if R^A[i] == R+A[i]:
        R ^= A[i]
        A[i] = 0
B = 0
for i in A:
    B ^= i        
print(R+B)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
C=0
for i in range(N):
    C=C^A[i]
B=0
for i in range(N):
    if A[i]^C==A[i]+C:
        B=B^A[i]
AND=(B^C)&B
print(2*AND+C)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 60

if N <= 20:
    ans = 0
    for i in range(1<<N):
        R = 0
        B = 0
        for j in range(N):
            if i & (1<<j):
                R ^= A[j]
            else:
                B ^= A[j]
        ans = max(ans, R+B)
    print(ans)
else:
    for a in A:
        for i in range(60):
            if a & 1:
                X[i] += 1
            a >>= 1
    ans = 0
    
    cnt2 = 0
    for i in range(60)[::-1]:
        if X[i] == 2:
            cnt2 += 1
    if cnt2 >= 3:
        s = 0
        while True:
            s += 1
        
        
    for i in range(60):
        if X[i] & 1:
            ans += 1<<i
        elif X[i]:
            ans += 1<<i+1
    print(ans)

Submission status: Wrong Answer

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

def trans2(n):
    A = bin(n)
    return A[2:]

A.sort(reverse=True)

max_l = len(trans2(A[0]))
C = [0 for _ in range(max_l)]
L = [0 for _ in range(max_l+1)]
B = []
for a in A:
    b = trans2(a)
    L[len(b)] += 1
    b = '0'*(max_l - len(b)) + b
    for l in range(max_l):
        if b[max_l-1-l] == '1':
            C[l] += 1
#print(C)
ans = 0
for i, c in enumerate(C):
    if c == 0:
        continue
    elif c%2 == 0:
        ans += 2**(i+1)
    else:
        ans += 2**i
if C[0] == 2:
    ans -= 2
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
x=a[-1]
y=a[-2]
z=0
for i in a[:-2]:z^=i
print(max(x^z+y,y^z+x))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 60

if N <= 20:
    ans = 0
    for i in range(1<<N):
        R = 0
        B = 0
        for j in range(N):
            if i & (1<<j):
                R ^= A[j]
            else:
                B ^= A[j]
        ans = max(ans, R+B)
    print(ans)
else:
    for a in A:
        for i in range(60):
            if a & 1:
                X[i] += 1
            a >>= 1
    print(X)
    min2 = 60
    cnt2 = 0
    for i in range(60):
        if X[i] == 2:
            cnt2 += 1
    if cnt2 >= 1:
        print(1//0)
    ans = 0
    for i in range(60):
        if X[i] & 1:
            ans += 1<<i
        elif X[i]:
            ans += 1<<i+1
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 60

if N <= 22:
    ans = 0
    for i in range(1<<N):
        R = 0
        B = 0
        for j in range(N):
            if i & (1<<j):
                R ^= A[j]
            else:
                B ^= A[j]
        ans = max(ans, R+B)
    print(ans)
else:
    for a in A:
        for i in range(60):
            if a & 1:
                X[i] += 1
            a >>= 1
    print(X)
    min2 = 60
    cnt2 = 0
    for i in range(60):
        if X[i] == 2:
            cnt2 += 1
    if cnt2 >= 2:
        print(1//0)
    ans = 0
    for i in range(60):
        if X[i] & 1:
            ans += 1<<i
        elif X[i]:
            ans += 1<<i+1
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
b = [0]*61
for e in a:
  t = e
  cnt = 0
  while t != 0:
    b[cnt] += t&1
    t >>= 1
    cnt += 1

ans = 0
for i, e in enumerate(b):
  if e>0 and e%2==1:
    ans += (1<<i)
  elif e>0 and e%2==0:
    ans += (1<<i)*2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Nums = list(map(int, input().split(" ")))

Reds  = 0
Blues = 0

Nums.sort(reverse=True)

for i in range(N):
    v = Nums[i]
    TestR = Reds ^ v
    TestB = Blues ^ v
    if TestR - Reds > TestB - Blues:
        Reds = TestR
    else:
        Blues = TestB

print(Reds+Blues)

Submission status: Wrong Answer

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

flag = [False]*N

ans = 0
for i in range(60)[::-1]:
    s = 0
    for j in range(N):
        s += A[j]>>i & 1
    if s%2==1:
        ans += 2**i
    else:
        if s>=2:
            ans += 2**(i+1)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 60

if N <= 21:
    ans = 0
    for i in range(1<<N):
        R = 0
        B = 0
        for j in range(N):
            if i & (1<<j):
                R ^= A[j]
            else:
                B ^= A[j]
        ans = max(ans, R+B)
    print(ans)
else:
    for a in A:
        for i in range(60):
            if a & 1:
                X[i] += 1
            a >>= 1
    print(X)
    min2 = 60
    cnt2 = 0
    for i in range(60):
        if X[i] == 2:
            cnt2 += 1
    if cnt2 >= 3:
        print(1//0)
    ans = 0
    for i in range(60):
        if X[i] & 1:
            ans += 1<<i
        elif X[i]:
            ans += 1<<i+1
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 60

if N <= 21:
    ans = 0
    for i in range(1<<N):
        R = 0
        B = 0
        for j in range(N):
            if i & (1<<j):
                R ^= A[j]
            else:
                B ^= A[j]
        ans = max(ans, R+B)
    print(ans)
else:
    for a in A:
        for i in range(60):
            if a & 1:
                X[i] += 1
            a >>= 1
    print(X)
    min2 = 60
    cnt2 = 0
    for i in range(60):
        if X[i] == 2:
            cnt2 += 1
    if cnt2 >= 5:
        print(1//0)
    ans = 0
    for i in range(60):
        if X[i] & 1:
            ans += 1<<i
        elif X[i]:
            ans += 1<<i+1
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 60

if N <= 19:
    ans = 0
    for i in range(1<<N):
        R = 0
        B = 0
        for j in range(N):
            if i & (1<<j):
                R ^= A[j]
            else:
                B ^= A[j]
        ans = max(ans, R+B)
    print(ans)
else:
    for a in A:
        for i in range(60):
            if a & 1:
                X[i] += 1
            a >>= 1
    print(X)
    min2 = 60
    cnt2 = 0
    for i in range(60):
        if X[i] == 2:
            cnt2 += 1
    if cnt2 >= 5:
        print(1//0)
    ans = 0
    for i in range(60):
        if X[i] & 1:
            ans += 1<<i
        elif X[i]:
            ans += 1<<i+1
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 60

if N <= 19:
    ans = 0
    for i in range(1<<N):
        R = 0
        B = 0
        for j in range(N):
            if i & (1<<j):
                R ^= A[j]
            else:
                B ^= A[j]
        ans = max(ans, R+B)
    print(ans)
else:
    for a in A:
        for i in range(60):
            if a & 1:
                X[i] += 1
            a >>= 1
    print(X)
    min2 = 60
    cnt2 = 0
    for i in range(60):
        if X[i] == 2:
            cnt2 += 1
    if cnt2 >= 3:
        print(1//0)
    ans = 0
    for i in range(60):
        if X[i] & 1:
            ans += 1<<i
        elif X[i]:
            ans += 1<<i+1
    print(ans)

Submission status: Wrong Answer

Solution code:
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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 60

if N <= 20:
    ans = 0
    for i in range(1<<N):
        R = 0
        B = 0
        for j in range(N):
            if i & (1<<j):
                R ^= A[j]
            else:
                B ^= A[j]
        ans = max(ans, R+B)
    print(ans)
else:
    for a in A:
        for i in range(60):
            if a & 1:
                X[i] += 1
            a >>= 1
    ans = 0
    for i in range(60):
        if X[i] & 1:
            ans += 1<<i
        elif X[i]:
            ans += 1<<i+1
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = 0
c = 1
for _ in range(62):
    d = 0
    for j in a:
        d += 1 if c & j > 0 else 0
    if d > 0:
        b += c
        if d & 1 == 0:
            b += c
    c *= 2
print(b)

Submission status: Wrong Answer

Solution code:
def find_max(f):
    for i in range(1, N):
        # f[1]をredにした場合
        val_red = (f[i-1][0] ^ A[i]) + f[i-1][1]

        # f[1]をblueにした場合
        val_blue = f[i-1][0] + (f[i-1][1] ^ A[i])

        if val_red > val_blue:
            f[i][0] = f[i-1][0] ^ A[i]
            f[i][1] = f[i-1][1]
        else:
            f[i][0] = f[i-1][0]
            f[i][1] = f[i-1][1] ^ A[i]

    return f[-1][0] + f[-1][1]


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

f = [[0,0] for i in range(N)]
f[0][0] = A[0]
# print('------')
print(find_max(f))

Submission status: Time Limit Exceeded

Solution code:
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):
        return len(bin(x))-2
    
    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:#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()

Submission status: Time Limit Exceeded

Solution code:
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():
    # https://tjkendev.github.io/procon-library/python/string/z-algorithm.html
    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():
    # 参考 prd_xxxさん
    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
    #print(even)
    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)
    #print(A2)
    ans = 0
    for key,e in even.items():
        if e==0:
            ans += 1<<key
    L = gauss_jordan(A2); L.sort(reverse=True)
    #print(ans)
    #print(L)
    now = L[0]
    for i in range(1,N):
        l = L[i]
        if l==0:
            break
        n = l.bit_length()-1
        #print(n,now)
        if now&(1<<n)>0:
            continue
        now ^= l
    #print(now)
    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()

"""

"""

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
alist=list(map(int,input().split()))
#alist.sort(reverse=True)

max_digit=60
mat=[]
xor_alist=0
or_alist=0
for a in alist:
  xor_alist^=a
  or_alist|=a
  array=[]
  for j in range(max_digit):    
    m=a&1
    array.append(m)
    a>>=1    
  array.reverse()
  mat.append(array)
#print(mat)

xor_digit=[0]*max_digit
or_digit=[0]*max_digit
for i in range(max_digit):
  xor_digit[-1-i]=xor_alist&1
  xor_alist>>=1
  or_digit[-1-i]=or_alist&1
  or_alist>>=1

mat_red=[[mat[i][j] for j in range(max_digit) if xor_digit[j]%2==0 and or_digit[j]==1] for i in range(N)]
#print(mat_red)

pivot_set=set()
for j in range(len(mat_red[0])):
  pivot_row=-1
  for i in range(N):
    if mat_red[i][j]==1 and not i in pivot_set:
      pivot_row=i
      break
  else:
    continue
  
  for i in range(N):
    if i==pivot_row:
      continue
    if mat_red[i][j]==0:
      continue      
    for k in range(j,len(mat_red[0])):
      mat_red[i][k]^=mat_red[pivot_row][k]
      
  pivot_set.add(pivot_row)
  #print(j,pivot_row)
  #print(mat_red)
#print(mat_red)  

sum_digit_red=[0]*len(mat_red[0])
for i in range(N):
  for j in range(len(mat_red[0])):
    sum_digit_red[j]^=mat_red[i][j]
#print(sum_digit_red)

answer=0
cnt=0
for j in range(max_digit):
  if or_digit[j]==0:
    continue
  if xor_digit[j]:
    answer+=2**(max_digit-1-j)
  else:
    if sum_digit_red[cnt]:
      answer+=2**(max_digit-j)
    cnt+=1
    
print(answer)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
alist=list(map(int,input().split()))
#alist.sort(reverse=True)

max_digit=60
mat=[]
sum_digit=[0]*max_digit
for a in alist:
  array=[]
  for j in range(max_digit):    
    m=a&1
    array.append(m)
    sum_digit[max_digit-1-j]+=m
    a>>=1
    
  array.reverse()
  mat.append(array)
#print(mat)
#print(sum_digit)

mat_red=[[mat[i][j] for j in range(max_digit) if sum_digit[j]%2==0 and sum_digit[j]!=0] for i in range(N)]
#print(mat_red)

pivot_set=set()
for j in range(len(mat_red[0])):
  pivot_row=-1
  for i in range(N):
    if mat_red[i][j]==1 and not i in pivot_set:
      pivot_row=i
      break
  else:
    continue
  
  for i in range(N):
    if i==pivot_row:
      continue
    if mat_red[i][j]==0:
      continue      
    for k in range(j,len(mat_red[0])):
      mat_red[i][k]^=mat_red[pivot_row][k]
      
  pivot_set.add(pivot_row)
  #print(j,pivot_row)
  #print(mat_red)
#print(mat_red)  

sum_digit_red=[0]*len(mat_red[0])
for i in range(N):
  for j in range(len(mat_red[0])):
    sum_digit_red[j]^=mat_red[i][j]
#print(sum_digit_red)

answer=0
cnt=0
for j in range(max_digit):
  if sum_digit[j]==0:
    continue
  if sum_digit[j]&1:
    answer+=2**(max_digit-1-j)
  else:
    if sum_digit_red[cnt]&1:
      answer+=2**(max_digit-j)
    cnt+=1
    
print(answer)

Submission status: Time Limit Exceeded

Solution code:
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]のi番目のbitを1にするswapでもいい
        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)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
alist=list(map(int,input().split()))
alist.sort(reverse=True)

max_digit=60
mat=[]
sum_digit=[0]*max_digit
for a in alist:
  array=[]
  for j in range(max_digit):    
    m=a&1
    array.append(m)
    sum_digit[max_digit-1-j]+=m
    a>>=1
    
  array.reverse()
  mat.append(array)
#print(mat)
#print(sum_digit)

mat_red=[[mat[i][j] for j in range(max_digit) if sum_digit[j]%2==0 and sum_digit[j]!=0] for i in range(N)]
#print(mat_red)

pivot_set=set()
for j in range(len(mat_red[0])):
  pivot_row=-1
  for i in range(N):
    if mat_red[i][j]==1 and not i in pivot_set:
      pivot_row=i
      break
  else:
    continue
  
  for i in range(N):
    if i==pivot_row:
      continue
    if mat_red[i][j]==0:
      continue      
    for k in range(j,len(mat_red[0])):
      mat_red[i][k]^=mat_red[pivot_row][k]
      
  pivot_set.add(pivot_row)
  #print(j,pivot_row)
  #print(mat_red)
#print(mat_red)  

sum_digit_red=[0]*len(mat_red[0])
for i in range(N):
  for j in range(len(mat_red[0])):
    sum_digit_red[j]^=mat_red[i][j]
#print(sum_digit_red)

answer=0
cnt=0
for j in range(max_digit):
  if sum_digit[j]==0:
    continue
  if sum_digit[j]&1:
    answer+=2**(max_digit-1-j)
  else:
    if sum_digit_red[cnt]&1:
      answer+=2**(max_digit-j)
    cnt+=1
    
print(answer)