Problem:


Score : 500 points

Problem Statement

There are N Snuke Cats numbered 1, 2, \ldots, N, where N is even.

Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.

Recently, they learned the operation called xor (exclusive OR).

What is xor?

For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:

 When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~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~\textrm{xor}~5 = 6.

They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.

We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i.
Using this information, restore the integer written on the scarf of each Snuke Cat.

Constraints

All values in input are integers.

2 \leq N \leq 200000

N is even.

0 \leq a_i \leq 10^9

There exists a combination of integers on the scarfs that is consistent with the given information.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_N

Output

Print a line containing N integers separated with space.

The i-th of the integers from the left should represent the integer written on the scarf of Snuke Cat i.

If there are multiple possible solutions, you may print any of them.

Sample Input 1

4
20 11 9 24

Sample Output 1

26 5 7 22

5~\textrm{xor}~7~\textrm{xor}~22 = 20

26~\textrm{xor}~7~\textrm{xor}~22 = 11

26~\textrm{xor}~5~\textrm{xor}~22 = 9

26~\textrm{xor}~5~\textrm{xor}~7 = 24

Thus, this output is consistent with the given information.



Sample input:
4
20 11 9 24


Sample output:
26 5 7 22

Submission status: Time Limit Exceeded

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

m = max(A).bit_length()
bits = [[] for _ in range(N)]
for i, v in enumerate(A):
    for j in range(m):
        bits[i].append(v>>j & 1)

res = [[] for _ in range(N)]
for p in zip(*bits):
    if sum(p)%2 == 1:
        for i in range(N):
            res[i].append(1-p[i])
    else:
        for i in range(N):
            res[i].append(p[i])


num = [0]*N
for i in range(N):
    for j in range(m):
        num[i] += res[i][j] * (2**j)

print(*num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
c = [0]*50
for i in a:
    s = format(i,'b')[::-1]
    for i in range(len(s)):
        c[i] += int(s[i])

buf = []
for i in a:
    s = format(i,'b').zfill(50)[::-1]
    ans = ''
    for i in range(50):
        ans +=  str((c[i]-int(s[i]))%2)
    ans = ans[::-1]
    buf.append(int(ans,2))

print(*buf)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().strip().split()))

m = len(bin(max(a))[2:])

p = np.zeros((n,m),dtype=int)

for i in range(n):
    bin_str = bin(a[i])[2:]
    p[i,m-len(bin_str):] = [int(s) for s in list(bin_str)]

#for i in range(n):
#    print(p[i,:])

q = np.zeros((n,m),dtype=int)

for j in range(m):
    if sum(p[:,j]) % 2 == 0:
        q[:,j] = p[:,j]
    else:
        for k in range(n):
            q[k,j] = not p[k,j]
#print()
#for i in range(n):
#    print(q[i,:])


for i in range(n):
    ans = int((str(q[i,:]).replace('[','').replace(']','').replace(' ','')),2)
    if i < n - 1:
        print(ans,end=' ')
    else:
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
n=int(input())
k=list(map(int,input().split()))
for i in range(n):
  c=k[:i]+k[i+1:]
  print(reduce(lambda a,b:a^b,c),end=" ")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n = int(input())
    a_list = input_to_int_tuple()

    ret = ""
    for i in range(n):
        my = 0
        for j, v in enumerate(a_list):
            if i == j:
                continue

            my ^= v

        ret += str(my) + " "

    print(ret.rstrip())


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
mx=len(bin(max(a)))
b=["0"*(mx-len(bin(x)))+bin(x)[2:] for x in a]

out=["" for _ in range(n)]
for i in range(mx-2):
    tot=0
    for j in range(n):
        tot+=int(b[j][i])
    tot=tot%2
    for j in range(n):
        if tot==int(b[j][i]):out[j]+="0"
        else : out[j]+="1"
c=[str(int(y,2)) for y in out]
print(" ".join(c))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=list(map(int,input().split()))
xor=[0]*N
for i in range(N):
    for j in range(N):
        if i!=j:
            xor[i]=xor[i]^a[j]
print(*xor)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n = int(input())
    a_list = input_to_int_tuple()

    ret = []
    for i in range(n):
        my = 0
        for j, v in enumerate(a_list):
            if i == j:
                continue

            my ^= v

        ret.append(my)

    print(" ".join(map(str, ret)))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
M=max(A)
l=[0]*31
count=0
while M>0:
    x=0
    for i in range(N):
        x+=(A[i]>>count&1)
    l[count]=x%2
    count+=1
    M=M//2
ans=[0]*N
for i in range(N):
    a=0
    count=1
    for j in range(31):
        if l[j]==0:
            if A[i]>>j&1:
                a+=count
        if l[j]==1:
            if not A[i]>>j&1:
                a+=count
        count*=2
    ans[i]=a
print(ans[0],end='')
for i in range(1,N):
    print(' '+str(ans[i]),end='')
print()

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

for i in range(n):
    tmp = a[:i] + a[i + 1:]
    print(reduce(lambda i, j: int(i) ^ int(j), tmp))

Submission status: Time Limit Exceeded

Solution code:
def two(x):
    lis=[]
    for i in range(50):
        lis.append(x%2)
        x=x//2
    return lis

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

tl=[]
for i in range(50):
    tl.append(2**i)

lis=[0 for i in range(50)]

for ai in a:
    for j in range(50):
        lis[j]=(lis[j]+two(ai)[j])%2

ans=[]
for ai in a:
    ansi=0
    for j in range(50):
        if two(ai)[j]!=lis[j]:
            ansi+=tl[j]
    ans.append(ansi)

print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
c=list(map(int,input().split()))
for i in range(len(c)):
	s=0
	for j in range(len(c)):
		if(j!=i):
			s=s^c[j]
	print(s,end=" ")
print()

Submission status: Time Limit Exceeded

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

rec = [0] * n

def check(k):
    off = []
    on = []
    flag = 0
    for i in range(n):
        if (a[i]>>k)&1:
            flag += 1
            on.append(i)
        else:
            off.append(i)

    if flag%2 == 0:
        for i in on:
            rec[i] += pow(2, k)
    else:
        for i in off:
            rec[i] += pow(2, k)

for i in range(31):
    check(i)
print(*rec)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = [int(x) for x in input().split()]
ans = []
for i, x in enumerate(arr):
    temp = 0
    for j, y in enumerate(arr):
        if i != j:
            temp = temp ^ y
    ans.append(temp)
for x in ans:
    print(x, end=" ")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
total = [0] * 31
for i in a:
    for j in range(31):
        if i >> j & 1:
            total[j] += 1
# print(total)
for i in a:
    ans = 0
    for j in range(31):
        if total[j] % 2 != (i >> j & 1):
            ans += 2 ** j
    print(ans, end=" ")
print()

Submission status: Time Limit Exceeded

Solution code:
import copy


n = int(input())
lst = list(map(int,input().split(' ')))

for i in range(n):
    l = copy.deepcopy(lst)
    del l[i]
    buf = 0
    for ll in l:
        buf ^= ll
    print(buf)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    BITS = 30
    sum_bit = [0] * BITS
    a_bits = []

    for a in a_list:
        bits = [a>> j & 1 for j in range(BITS)]
        for i, bit in enumerate(bits):
            sum_bit[i] += bit
        a_bits.append(bits)

    for a_bit in a_bits:
        # rb -> sum_bitのビット, ab -> a_bitのビット
        res = 0
        cur = 1
        for i in range(BITS):
            res += cur if (a_bit[i] + sum_bit[i])%2 == 1 else 0
            cur *= 2
        print(res, end=" ")

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

result = []

for i in range(N):
    if i == 0:
        s = A[1]
        for j in range(2,N):
            s = s ^A[j]
    else:
        s = A[0]
        for j in range(1, N):
            if j != i:
                s = s ^ A[j]  
    result.append(str(s))

print(' '.join(result))

Submission status: Time Limit Exceeded

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

xorall = 0
for i in xorz:
    xorall ^= i

res = ""
for i in range(N):
    numx = xorall ^ xorz[i]
    res += str(numx)
    if i < N-1:
        res += " "


print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().rstrip().split(" ")))
bit = [0 for i in range(32)]
for i in range(32):
    for i2 in A:
        if (i2 >> i) & 1:
            bit[i] += 1
ans = [0 for i in range(len(A))]
for i in range(32):
    for i2 in range(len(A)):
        if bit[i] % 2 == 0:
            if (A[i2] >> i) & 1:
                ans[i2] += 2 ** i
        else:
            if not (A[i2] >> i) & 1:
                ans[i2] += 2 ** i
print(" ".join(map(str,ans)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
def f(x):
  c=[x[i-1]^x[i]for i in range(1,n)]
  k=[x[1:].count(1)%2]
  for i in c:
    k.append(k[-1]^i)
  return k
for i in range(31):
  t=1<<i
  x=[]
  for j in a:
    if t&j:x.append(1)
    else:x.append(0)
  m=f(x)
  for j in range(n):ans[j]+=t*m[j]
print(*ans)

Submission status: Time Limit Exceeded

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

result = []
for i in range(0, n):
    temp = 0
    for j in range(0, n):
        if i != j:
            temp ^= A[j]
    result += [str(temp)]
print(' '.join(result))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
L = []
x=0
for a in A:
    x ^= a
    L.append(x)
R = []
x=0
for a in reversed(A):
    x ^= a
    R.insert(0, x)
for i in range(n):
    x = 0
    if i>0:
        x^=L[i-1]
    if i<n-1:
        x^=R[i+1]
    print(x, end="")
    if i==n-1:
        print("")
    else:
        print(" ",end="")

Submission status: Time Limit Exceeded

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
tot=0
for a in A:
  tot^=a
T=[0]*30
for i in range(30):
  if tot&(1<<i):
    T[i]=1

Ans=[0]*n
for i in range(n):
  cur=0
  for j in range(30):
    if A[i]&(1<<j)>0 and T[j]==0:
      cur+=2**j
    elif A[i]&(1<<j)==0 and T[j]==1:
      cur+=2**j
  Ans[i]=cur
print(*Ans)

Submission status: Time Limit Exceeded

Solution code:
def xor_operate(a_list):
    result = 0
    for a in a_list:
        result ^= int(a)
    return str(result)



if __name__ == "__main__":
    N = input()
    a_list = input()

    a_list = a_list.split(" ")

    i_list = []
    for i in range(len(a_list)):
        r_list = a_list[:i]+a_list[i+1:]
        i_list.append(xor_operate(r_list))
    print(" ".join(i_list))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
al=0
for i in a:
  al=al^i
r=""
for i in a:
  r+=str(i^al)+" "
print(r[:-1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
pari = [0] * 40
for i in range(40):
    for j in a:
        pari[i] += (j&(1<<i))>>i

ans = a[:]

for i in range(40):
    if pari[i]%2:
        for j in range(n):
            if a[j]&(1<<i):
                ans[j] -= 1<<i
            else:
                ans[j] += 1<<i

print(' '.join([str(i) for i in ans]))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
res=0
for i in range(n):
  res^=a[i]
ans=[]
for i in range(n):
  ans.append(res^a[i])
print(*ans)

Submission status: Accepted

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

cnt=0
for i in range(N):
    cnt=cnt^a[i]

B=[]*N
for i in range(N):
    ans=cnt^a[i]
    B.append(str(ans))

print(' '.join(B))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
xor = 0
for i in range(N):
    xor ^= A[i]
anslis = []
for i in range(N):
    answer = xor^A[i]
    anslis.append(answer)
print(' '.join(map(str,anslis)))

Submission status: Accepted

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

tmp = 0
for aa in a:
    tmp ^= aa
ans = [tmp ^ aa for aa in a]
print(*ans)

Submission status: Accepted

Solution code:
from functools import reduce

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

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

ans = []
for a in A:
    ans.append(B^a)

print(*ans)

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline
from collections import Counter
def solve():
    N = int(input())
    a = list(map(int,input().split()))
    assert N & 1 == 0
    s = 0
    res = []
    for v in a:
        s ^= v
    for v in a:
        res.append(s^v)
    print(' '.join(map(str,res)))







if __name__ == '__main__':
    solve()