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:
from functools import reduce
n=int(input())
l=list(map(int,input().split()))
res=[]
b=[]
for i in range(len(l)):
    b=l[0:i]+l[i+1:]
    res.append(reduce(lambda x,y:x^y,b))
print(*res)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
    At=A[:i]+A[i+1:]
    tmp=At.pop(0)
    for a in At:
        tmp=tmp^a
    print(tmp,end=" ")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
S = 0
for i in range(N):
    S ^= a[i]

Ans = ""
for i in range(N):
    Ans = Ans + str(S^a[i]) + " "

print(Ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
sumn=[0]*30
lis=[]
for i in range(n):
  ans=""
  fa=a[i]
  for i in range(0,30):
    check=29-i
    ww=fa//(2**check)
    ans+=str(ww)
    fa%=(2**check)
    sumn[i]+=ww
  lis.append(ans)

for j in range(0,n):
  check=lis[j]
  res=0
  for i in range(0,30):
    jyou=29-i
    ukeru=check[i]
    ukeru=int(ukeru)
    keisu=(sumn[i]-ukeru)%2
    res+=keisu*(2**jyou)
  if j!=n-1:
    print(res,end=" ")
  else:
    print(res)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
sumn=[0]*30
lis=[]
for i in range(n):
  ans=""
  fa=a[i]
  for i in range(0,30):
    check=29-i
    ww=fa//(2**check)
    ans+=str(ww)
    fa-=ww*(2**check)
    sumn[i]+=ww
  lis.append(ans)

for j in range(0,n):
  check=lis[j]
  res=0
  for i in range(0,30):
    jyou=29-i
    ukeru=check[i]
    ukeru=int(ukeru)
    keisu=(sumn[i]-ukeru)%2
    res+=keisu*(2**jyou)
  if j!=n-1:
    print(res,end=" ")
  else:
    print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
S = 0
for i in range(N):
    S = S^a[i]

Ans = ""
for i in range(N):
    Ans = Ans + str(S^a[i]) + " "

print(Ans)

Submission status: Time Limit Exceeded

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

def ten_to_bi(n):
    result_of_binary = ""
    while n>0:
        result_of_binary = result_of_binary + str(int(n%2))
        n = int((n-(n%2))/2)
    return(result_of_binary)

def bi_to_ten(bi):
    result_of_ten = 0
    for i in range(len(bi)):
        result_of_ten = result_of_ten + int(bi[i])*(2**i)
    return(result_of_ten)

def xor_bi(n,m):
    result_of_xor_bi = ""
    if len(m)>len(n):
        temp=n
        n,m = m,temp
    for i in range(len(n)-len(m)):
        m = m + "0"
    for i in range(len(n)):
        if n[i]==m[i]:
            result_of_xor_bi = result_of_xor_bi + "0"
        else:
            result_of_xor_bi = result_of_xor_bi + "1"
    return(result_of_xor_bi)
    
b = [ten_to_bi(a[i]) for i in range(N)]
c = "0"
for i in range(N-1):
    c = xor_bi(c,b[i+1])
d=[bi_to_ten(c)]

for i in range(N-1):
    c = xor_bi(c,xor_bi(b[i],b[i+1]))
    d.append(bi_to_ten(c))

Ans = ""
for i in range(N):
    Ans = Ans + str(d[i]) + " "

print(Ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

for i in range(n):
  b[i] = reduce(lambda x,y : x^y,a[0:i+1]+a[i:])

print(" ".join(list(map(str,b))))

Submission status: Time Limit Exceeded

Solution code:
import functools
N = int(input())
numbers = list(map(int,input().split()))
xor = ''
for i in range(len(numbers)):
    othersNumbers = numbers[:i] + numbers[i + 1:]
    currentXor = 0
    xor += str(functools.reduce(lambda x,y:x^y,othersNumbers)) + ' '
    
print(xor)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
numbers = list(map(int,input().split()))
xor = ''
for i in range(len(numbers)):
    othersNumbers = numbers[:i] + numbers[i + 1:]
    currentXor = 0
    for num in othersNumbers:
        currentXor ^= num
    xor += ' ' + str(currentXor) + ' '
print(xor)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))

# aを2進数化
# 2 ** 29 < 10 ** 9 < 2 ** 30
k = 30 # 2進数変換後の最大桁数
s = a[0]
x_str = ""
for i in range(N-1):
  s = s ^ a[i+1]
for i in range(N-1):
  x = s ^ a[i]
  x_str += str(x) + " "
x_str += str(s ^ a[N-1])
print(x_str)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))

# aを2進数化
# 2 ** 29 < 10 ** 9 < 2 ** 30
k = 30 # 2進数変換後の最大桁数
a_binary = [[0] * k for _ in range(N)]
for i in range(N):
  quotient = a[i]
  remainder = 0
  for j in range(k):
    remainder = quotient % 2
    quotient = quotient // 2
    a_binary[i][j] = remainder
s = [0] * k # a1 xor a2 xor ~ xor aN
for i in range(k):
  count_1 = 0
  for j in range(N):
    if a_binary[j][i] == 1:
      count_1 += 1
  if count_1 % 2 == 1:
    # 1が奇数個の場合
    s[i] = 1
  else:
    s[i] = 0
x_binary = [[0] * k for _ in range(N)]
for i in range(N):
  for j in range(k):
    if a_binary[i][j] + s[j] == 1:
      x_binary[i][j] = 1
    else:
      x_binary[i][j] = 0
x_str = ""
for i in range(N):
  xi = 0
  for j in range(k):
    t = 2 ** j
    xi += x_binary[i][j] * t
  x_str += str(xi)
  if i != N-1:
    x_str += " "

print(x_str)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ans = [0] * N
for i,a in enumerate(A):
    for n in range(N):
        if i == n:
            pass
        else:
            ans[n] = ans[n]^a
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
A = l()
ans = []

for i in itertools.combinations(A,N-1):
    a = 0
    for j in i:
        a = a ^ int(j)
    ans.append(str(a))
ans.reverse()
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
xor_arr = list(map(int, input().split()))
xor_of_xor = 0
for elm in xor_arr:
    xor_of_xor = xor_of_xor ^ elm
    scarf_val = [xor_of_xor ^ elm for elm in xor_arr]
         
print(" ".join(str(x) for x in scarf_val))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
bit_num = 30
A_b = [format(a, '0{}b'.format(bit_num)) for a in A]
S = ''
for i in range(bit_num):
    bit = 0
    for a in A_b:
        if a[i] == '1':
            bit += 1
    if bit % 2 == 0:
        S += '0'
    else:
        S += '1'
#print(S)
B = []
for a in A_b:
    b = ''
    for i in range(bit_num):
        if (int(a[i]) + int(S[i])) % 2 == 0:
            b +='0'
        else:
            b += '1'
    #print(b)
    B.append(int(b, 2))
print(*B)

Submission status: Time Limit Exceeded

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

ma = max(a)
tmp = 1
m = ma.bit_length()

memo = [0 for i in range(m+1)]

for j in range(m+1):
    cnt0 = 0
    cnt1 = 0
    for ai in a:
        if ai & (1 << j):
            cnt1 += 1
        else:
            cnt0 += 1
    if cnt1 % 2 == 0 and cnt0 % 2 == 0:
        memo[j] = 1

ans = []


for ai in a:
    ansi = 0
    for j in range(m+1):
        if ai & (1 << j):
            if memo[j]:
                ansi += 2 ** j
        else:
            if memo[j] == 0:
                ansi += 2 ** j

    ans.append(str(ansi))

print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
answer = [0] * N
for i in range(N):
    tmp = a[:i] + a[i+1:]
    ans = tmp[0]
    for j in range(1, len(tmp)):
        ans = ans ^ tmp[j]
    answer[i] = ans
    
print(' '.join(map(str, answer)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
l = [0] * 30
b = []
for i in range(n):
  x = a[i]
  t = ''
  j = 29
  while j >= 0:
    if x < 2**j:
      t += '0'
    else:
      x -= 2**j
      t += '1'
      l[j] += 1
    j -= 1
  b.append(t)
ans = []
for i in range(n):
  t = b[i]
  d = 0
  for j in range(30):
    k = l[j]
    if t[-(j+1)] == '1':
      k += 1
    k %= 2
    d += k * 2**j
  ans.append(d)
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline

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

for j in range(n):
  b = 0
  for i, v in enumerate(a):
    if i != j:
      b ^= v
  print(b)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
L = [0]*(N+1)
R = [0]*(N+1)
for i in range(N):
  L[i+1] = L[i]^a[i]
  R[N-i-1] = R[N-i]^a[N-i-1]
  ans = [None]*N
for i in range(N):
  ans[i] = L[i]^R[i+1]
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
m = max(a)
count = 0
nishin = []

while True:
    m, r = divmod(m, 2)
    count += 1
    if m == 0:
        break

for i in range(0, N):
    for j in range(0, count):
        a[i], r = divmod(a[i], 2)
        nishin.append(str(r))
    a[i] = ''.join(reversed(nishin))
    nishin.clear()

for k in range(0, N):
    q = ''
    for j in range(0, count):
        p = 0
        for i in range(0, N):
            if i == k:
                pass
            else:
                p += int(a[i][j])
        p %= 2
        q += str(p)
    nishin.append(q)

jusshin = [int(i, 2) for i in nishin]

ans = ''

for i in range(0, N-1):
    ans += (str(jusshin[i]) + ' ')

ans += str(jusshin[N-1])
print(ans)

Submission status: Time Limit Exceeded

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

ans = []
for i in range(N):
    a = 0
    for j in range(N):
        if i != j:
            a ^= A[j]
    ans.append(str(a))

print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
from copy import copy

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

def all_xor(l):
    l = copy(l)
    while len(l) != 1:
        l[0] ^= l[1]
        l.pop(1)
    return l[0]

s = all_xor(a)
print(' '.join(map(str, [s ^ i for i in a])))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = 0
for x in a: s ^= x

ans = [0] * n
for i in range(n):
    res = 0
    x, y = a[i], s
    for j in range(50):
        if x % 2 != y % 2: res += 2**j
        x >>= 1
        y >>= 1
    ans[i] = res

print(*ans)

Submission status: Time Limit Exceeded

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

for x in a:
    s = s ^ x

ans = ''
for x in a:
    ans = ans + str(s ^ x) + ' '
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def xor_sum(ls):
  f=0
  for i in ls:
    f=f^i
  return f

n = int(input())
l = list(map(int,input().split()))
for i in range(n):
  print(xor_sum(l[:i]+l[i+1:]),end="")
  if i!=n-1:
  	print(" ",end="")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

listp = [[0 for j in range(31)] for i in range(N)] 
li = [0]*31
for i in range(N):
    for j in range(30,-1,-1):
        if A[i] >= 2**j:
            listp[i][j] = 1
            A[i] -= 2**j
            li[j] = li[j]+1
            if li[j] > 2:
                li[j] = 1
for i in range(N):
    ans = 0
    for j in range(31):
        if li[j] - listp[i][j] == 1:
            ans += 2**j
    print(ans, end=" ")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
m =max(a)
# print(format(m, 'b'))
# print(len(str(format(m, 'b'))))
x = len(str(format(m, 'b')))
s = [False]*x
for i in a:
    t = str(format(i, 'b'))
    for j in range(len(t)):
        if t[j]=="1":
            # print(j)
            s[j+x-len(t)]= not s[j+x-len(t)]
# y = s.copy()
# print(y)
for i in a:
    y = s.copy()
    t = str(format(i, 'b'))
    for j in range(len(t)):
        if t[j]=="1":
            # print("hai")
            y[j+x-len(t)]= not y[j+x-len(t)]
    # print(y)
    y = ["1"  if i==True else "0" for i in y]
    # print(y)
    ans = ""
    for i in y:
        ans +=i
    # print(ans)
    print(int(ans,2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
allxor = 0
for i in range(n):
    allxor = allxor^a[i]
ans = ''
for i in range(n):
    ans= ans +str(allxor^a[i])+' '
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


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


def main():
    N = int(input())
    A = inpl()
    lx = 30
    tmp = [0] * lx

    for a in A:
        for i in range(lx):
            if (a >> i) % 2 == 1:
                tmp[i] = (tmp[i] + 1) % 2

    ans = []
    for a in A:
        b = 0
        for i in range(lx):
            if tmp[i] == 0 and (a >> i) % 2 == 1:
                b += 2**i
            elif tmp[i] == 1 and (a >> i) % 2 == 0:
                b += 2**i
        ans.append(b)
    print(*ans)

    return


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
cnt = 0
cntcnt = 0
new = []
for i in range(N):
  num = 0
  l = list(range(N))
  l.remove(l[i])
  for j in l:
    if cntcnt == 0:
      num = a[j]
    else:
      num = a[j]^num
    cntcnt += 1
  new.append(num)
  cnt += 1
print(' '.join(map(str, new)))

Submission status: Time Limit Exceeded

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

a0b=[0]*n
c=[0]*30
for i in range(n):
    a0b[i]=bin(a[i])
    st=str(a0b[i])
    for j in range(len(st)-2):
        z=a0b[i][-1-j]
        z=int(z)
        c[j]+=z

c_al=[0]*30
al=0
for i in range(len(c)):
    if c[i]%2==1:
        al+=2**i

#c_alは全体の排他的論理和
ans=[0]*n
for i in range(n):
    ans[i]=al^a[i]
L=[str(a) for a in ans]
L=" ".join(L)
print(L)

Submission status: Time Limit Exceeded

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

s = []
for i in range(n):
  k = 0
  for j in range(n):
    if (i==j):
      continue
    k = k^a[j]
  s.append(k)
  
print(*s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
acount = [0]*31

def binlist(x, acount):
    anslist = [0]*31
    tmp = 0
    while x > 0:
        if x % 2 == 1:
            acount[tmp] += 1
        anslist[tmp] = (x % 2)
        x = x // 2
        tmp += 1
    return anslist

abin = []
for i in a:
    abin.append(binlist(i, acount))

ans = []
for i in range(n):
    ans.append([])

anscnt = 0
for li in abin:
    tmp = 0
    for i in li:
        if acount[tmp] % 2 == 0:
            ans[anscnt].append(i)
        else:
            if i == 0:
                ans[anscnt].append(1)
            else:
                ans[anscnt].append(0)
        tmp += 1
    anscnt += 1

anscnt = 0
for li in ans:
    ans10 = 0
    tmp = 0
    for i in li:
        if i == 1:
            ans10 += 2**tmp
        tmp += 1
    if anscnt == n-1:
        print(ans10)
        print("")
    else:
        print(ans10, end=" ")
    anscnt += 1

Submission status: Time Limit Exceeded

Solution code:
# ABC171 E 

import itertools

n = int(input())
a_l = [list(format(int(x), "030b")) for x in input().split()]

for _d,_tp in enumerate(zip(*a_l)):
    if "1" not in _tp:
        continue
    if "0" not in _tp:
        continue
    else:
        _num = _tp.count("0")
        if _num % 2 == 1:
            for i in range(n):
                if a_l[i][_d] == "0":
                    a_l[i][_d] = "1"
                else:
                    a_l[i][_d] = "0"

print(*[int("".join(x), 2) for x in a_l])

Submission status: Time Limit Exceeded

Solution code:
# ABC171 E 

import itertools

n = int(input())
a_l = [format(int(x), "030b") for x in input().split()]

for _d,_tp in enumerate(zip(*a_l)):
    if "1" not in _tp:
        continue
    if "0" not in _tp:
        continue
    else:
        _num = _tp.count("0")
        if _num % 2 == 1:
            for i in range(n):
                _list = list(a_l[i])
                if _list[_d] == "0":
                    _list[_d] = "1"
                else:
                    _list[_d] = "0"
                a_l[i] = "".join(_list)

print(*[int(x, 2) for x in a_l])

Submission status: Time Limit Exceeded

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


listp = [[0 for j in range(31)] for i in range(N)] 
li = [0]*31
for i in range(N):
    for j in range(30,-1,-1):
        if A[i] >= 2**j:
            listp[i][j] = 1
            A[i] -= 2**j
            li[j] = li[j]+1
            if li[j] > 2:
                li[j] %= 2
for i in range(N):
    ans = 0
    for j in range(31):
        if li[j] - listp[i][j] %2 == 1:
            ans += 2**j
    print(ans, end=" ")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = []
for i in range(n):
    a[i] = list(format(a[i], '030b'))
for j in range(30):
    p = 0
    for i in range(n):
        a[i][j] = int(a[i][j])
        p += a[i][j]
    if p % 2 != 0:
        for u in range(n):
            a[u][j] = str(1-a[u][j])
    else:
        for u in range(n):
            a[u][j] = str(a[u][j])
for i in range(n):
    r = int(''.join(a[i]), 2)
    ans.append(r)
for i in range(n):
    print(ans[i],end= ' ')

Submission status: Time Limit Exceeded

Solution code:
# ABC171 E 

import itertools

n = int(input())
a_l = [list(format(int(x), "030b")) for x in input().split()]

a_l = list(zip(*a_l))

for _d,_tp in enumerate(a_l):
    if "1" not in _tp:
        continue
    if "0" not in _tp:
        continue
    else:
        _num = _tp.count("0")
        if _num % 2 == 1:
            a_l[_d] = ["1" if x == "0" else "0" for x in a_l[_d]]

a_l = list(zip(*a_l))
print(*[int("".join(x), 2) for x in a_l])

Submission status: Time Limit Exceeded

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

nums2 = []

def Base_10_to_n(X, n):
    X_dumy = X
    out = []
    while X_dumy>0:
        out.append(X_dumy%n)
        X_dumy = int(X_dumy/n)
    out.reverse()
    return out

for num in nums:
    nums2.append(Base_10_to_n(num, 2))

keta_max=0
for num2 in nums2:
    if keta_max<len(num2):
        keta_max = len(num2)

for num2 in nums2:
    while len(num2) < keta_max:
        num2.insert(0,0)

new_arr = [0]*keta_max
for num2 in nums2:
    for keta in range(keta_max):
        new_arr[keta] +=num2[keta]

ans_arr = [0]*keta_max
for index in range(N):
    ans=0
    for keta in range(keta_max):
        ans_arr[keta] =new_arr[keta] - nums2[index][keta]
    for keta in range(keta_max):
        if ans_arr[keta] %2 ==1:
            ans_arr[keta]=1
        else:
            ans_arr[keta]=0
    for index, ans_num in enumerate(reversed(ans_arr)):
        ans += ans_num*(2**index)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# ABC171 E 

import itertools

n = int(input())
a_l = [format(int(x), "030b") for x in input().split()]

for _d,_tp in enumerate(zip(*a_l)):
    if "1" not in _tp:
        continue
    if "0" not in _tp:
        continue
    else:
        _num = _tp.count("0")
        if _num % 2 == 1:
            for i in range(n):
                _str = list(a_l[i])
                if _str[_d] == "0":
                    _str[_d] = "1"
                else:
                    _str[_d] = "0"
                a_l[i] = "".join(_str)

print(*[int(x, 2) for x in a_l])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = input().split()
l = [0] * 30
for i in range(n):
	a[i] = format(int(a[i]), "030b")
	for j in range(30):
		l[j] += int(str(a[i])[j])
for i in range(30):
	l[i] = l[i] % 2
b = ""
for i in range(30):
	b += str(l[i])
b = int(b, 2)
for i in range(n):
	a[i] = b ^ int(a[i], 2)
print(" ".join(map(str, a)))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
arr = list(map(int,list(input().split())))
ds = set(arr)
############################################

allxor=0
for i in range(N):
	#allxor=allxor ^ ds.pop()
	allxor=allxor ^ arr[i]

for i in range(N):
	if i==0 :
		s=str(allxor ^ arr[i])
	else:
		s=s + ' ' + str((allxor ^ arr[i]))

print(s)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
a = np.fromstring(input(), sep=" ", dtype=np.int64)
# b = np.bitwise_xor.reduce(a)
# c = np.bitwise_xor(a, b)
# print(*c, sep=" ")
for n in range(N):
    print(np.bitwise_xor.reduce(a) ^ a[n])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
b = ["" for i in range(N)]

def int_to_2(X):
    r = ""
    while X>0:
        r = r + str(X%2)
        X = int((X- X%2)/2)
    return(r)
    
def xor(a,b):
    rr = ""
    r = 0
    aa = int_to_2(a)
    bb = int_to_2(b)
    if len(bb) > len(aa):
        cc = bb
        bb = aa
        aa = cc
    for i in range(len(aa)-len(bb)):
        bb = bb + "0"
    for i in range(len(aa)):
        if aa[i]!=bb[i]:
            rr = rr + "1"
        else:
            rr = rr + "0"
    for i in range(len(aa)):
        r = r + (2**i)*int(rr[i])
    return(r)

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

for i in range(N-1):
    ans[0] = xor(ans[0],a[i+1])

for i in range(N-1):
    ans[i+1] = xor(ans[i],xor(a[i],a[i+1]))

writeout = ""

for i in range(N):
    writeout = writeout + str(ans[i]) + " "

print(writeout)

Submission status: Time Limit Exceeded

Solution code:
# ABC171 E 

import itertools

n = int(input())
a_l = [format(int(x), "030b") for x in input().split()]

for _d,_tp in enumerate(zip(*a_l)):
    if "1" not in _tp:
        continue
    if "0" not in _tp:
        continue
    else:
        _l = list(_tp)
        _l.sort()
        gr = itertools.groupby(_l)
        _num = 0
        for key, group in gr:
            if key == "0":
                _num = len(list(group))
        if _num % 2 == 1:
            for i in range(n):
                _str = list(a_l[i])
                if _str[_d] == "0":
                    _str[_d] = "1"
                else:
                    _str[_d] = "0"
                a_l[i] = "".join(_str)

print(*[int(x, 2) for x in a_l])

Submission status: Time Limit Exceeded

Solution code:
#5問目
N = int(input())
a = list(map(int, input().split()))
#XORはpythonでは^で表現
temp = 0
result = []
for i in range(N):
    for j in range(len(a)):
        if j != i:
            temp = temp ^ a[j]
    result.append(temp)
    temp = 0
result=[str(a) for a in result]
result=" ".join(result)
print(result)

Submission status: Time Limit Exceeded

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

for i in range(N):
    ans = 0
    for j in range(30):
        x = 0
        for k in range(N):
            if i == k:
                continue
            if A[k] >> j & 1:
                x += 1
        if x % 2 == 1:
            ans += 2**j
    print(ans, end = " ")

Submission status: Time Limit Exceeded

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

    res = []
    xorSum = 0

    for i in range(0,N-1):
        xorSum ^= A[i]
    
    res.append(xorSum)

    for i in range(N-1):
        xorSum = xorSum ^ A[::-1][i] ^ A[::-1][i+1]
        res.append(xorSum)
    
    print(" ".join(map(str, res[::-1])))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = [0]*n
for i in range(30):# 桁
    count = 0
    check = [0]*n
    for j in range(n): # aのi桁目
        bit =  (a[j]>>i)&1
        count += bit
        check[j] += bit
    if count%2 == 0:
        for k in range(n):
            ans[k] += check[k]*(2**i)
    else:
        for k in range(n):
            ans[k] += abs(check[k]-1)*(2**i)

            
print(*ans)

Submission status: Time Limit Exceeded

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

k = len(bin(max(a)))-2
for x in a:
    b.append([int(y) for y in list(bin(x)[2:].zfill(k))])

b = np.array(b)
c = b.T

ans = []
for i in range(k):
    one = sum(c[i])
    if one%2==0:
        pass
    else:
        c[i] = (c[i]+1)%2

d = c.T

for i in range(n):
    ans.append(int(''.join([str(y) for y in d[i]]),2))

print(*ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lis = list(map(int, input().split()))
def calc(vals):
    val, *vals = vals
    for v in vals:
        val ^= v
    return val
ans = []
for n in range(len(lis)):
    ans.append(calc(lis[:n] + lis[n + 1:]))
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[list(str(bin(int(i)))) for i in input().split()]
count=[[0] for i in range(n)]
for i in range(n):
    for j in range(n):
        if(i==j):
            continue
        for k in range(1,len(a[j])-1):
            if(len(count[i])<k):
                count[i].insert(0,0)
            if(a[j][-k]=="1"):
                count[i][-k]=(1+count[i][-k])%2
            
for i in count:
    ans=0
    for j in range(len(i)-1,-1,-1):
        ans+=i[len(i)-1-j]*2**j
    print(ans,end=" ")

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
kotae=[]
for i in range(n):
    p=a[:i]+a[i+1:]
    ans=p[0]
    for j in range(1,len(p)):
        ans=ans^p[j]
    kotae.append(ans)
print(" ".join(map(str,kotae)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
aa=[]
for i in range(n):
    ans=0
    for j in a:
        if j!=a[i]:
            ans^=j
    aa.append(ans)
    ans=0
print(" ".join(map(str,aa)))

Submission status: Time Limit Exceeded

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

for i in range(N):
    ans = 0
    for j in range(40):
        x = 0
        for k in range(N):
            if i == k:
                continue
            if A[k] >> j & 1:
                x += 1
        if x % 2 == 1:
            ans += 2**j
    print(ans, end = " ")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
a = np.fromstring(input(), sep=" ", dtype=np.int64)
for n in range(N):
    print(np.bitwise_xor.reduce(a) ^ a[n])

Submission status: Time Limit Exceeded

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

for i in range(N):
    ans = 0
    for j in range(60):
        x = 0
        for k in range(N):
            if i == k:
                continue
            if A[k] >> j & 1:
                x += 1
        if x % 2 == 1:
            ans += 2**j
    print(ans, end = " ")

Submission status: Time Limit Exceeded

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

#A_bin = [bin(x)[2:] for x in A]
#A_bin = [bin(x) for x in A]
#maxlen = max([len(x) for x in A_bin])
#A_bin = [x.zfill(maxlen) for x in A_bin]

ans = ["" for _ in range(N)]
#ans[0] = str(0)
#A0 = A[0]
for i in range(N):
    AA = A[:i]
    AA.extend(A[i+1:])
    xor = "0b0"
    for aa in AA:
        xor = bin(int(xor,0)^aa)
#    xor = bin(A0 ^ A[i])
    ans[i] = str(int(xor,0))
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    l = len(format(max(a),'b'))
    a = [format(a[i],'0{}b'.format(l)) for i in range(n)]
    ans = [[] for i in range(n)]
    for i in range(l):
        s = 0
        for j in range(n):
            s+=int(a[j][i])
        if s%2!=0:
            for j in range(n):
                ans[j].append(str((int(a[j][i])+1)%2))
        else:
            for j in range(n):
                ans[j].append(a[j][i])
    for i in range(n):
        ans[i] = ''.join(ans[i])
        ans[i] = str(int(ans[i],2))
    print(' '.join(ans))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = list(map(int,input().split()))
a = np.array(a,dtype=np.int64)
b = [((a>>i)&1).sum() for i in range(31)]
li = []
for i in a:
    c = np.array([((i>>j)&1) for j in range(31)],dtype=np.int64)
    d = b-c
    point = 0
    for i in range(31):
        if d[i]%2 == 1:
            point += 2**(i)
    li.append(point)

print(*li)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
tmp=[]
for i in range(n):
    aa = a.copy()
    aa.pop(i)
    ans = aa[0]
    for j in range(1,len(aa)):
        ans ^= aa[j]
    tmp.append(ans)

print(*tmp)

Submission status: Time Limit Exceeded

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

ans = [0] * n
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        ans[i] ^= a[j]

print(*ans)

Submission status: Time Limit Exceeded

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


for i in range(N):
  s = 0
  for j in range(N):
    if j != i:
      s ^= A[j]
  print(s)