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: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
ans=[['']*30 for _ in range(N)]
i=29

while True:
    curbit=[aa%2 for aa in a]

    s=sum(curbit)
    if s==0:
        break

    if s%2==0:
        for j in range(N):
            ans[j][i]=str(curbit[j])
    else:
        for j in range(N):
            ans[j][i]=str(0 if curbit[j] else 1)


    a=[aa//2 for aa in a]
    i-=1

print(' '.join([str(int(''.join(aa),2)) for aa in ans]))

Submission status: Runtime Error

Solution code:
def to2d(n, len):
  d = [0]*len
  for i in range(len):
    idx = len-1-i
    d[idx] = int(n / (2**idx))
    n -= d[idx] * (2**idx)
  return d

def tonum(ds, ln):
  rep = 0
  for i in range(ln):
    rep += 2**i * ds[i]
  return rep

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

ds = [[0]*n for _ in range(30)]
for i in range(n):
  ds[i] = to2d(a[i], 30)

for dg in range(30):
  sum = 0
  for i in range(1, n):
    sum += ds[i][dg]
  
  if sum % 2 != ds[0][dg]:
    for i in range(n):
      ds[i][dg] = (ds[i][dg]+1) % 2

ans = [0]*n
for i in range(n):
  ans[i] = tonum(ds[i], 30)

print(' '.join(map(str, ans)))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = sum(A)
Q = int(input())
for i in range(Q):
  B, C = map(int, input().split())
  c = A.count(B)
  ans = ans - c * (B - C)
  A = [C if j == B else j for j in A]
  print(ans)

Submission status: Runtime Error

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

for i in range(N):
  for j in range(N):
    if i == j:
      continue
    O[i] ^= A[j]

print(O)

Submission status: Runtime Error

Solution code:
import math

n=int(input())
a_array=list(map(int,input().split()))
next_xor=[0 for _ in range(n-1)]
max_dig=math.floor(math.log2(a_array[0]))
for i in range(n-1):
    next_xor[i]=a_array[i]^a_array[i+1]
    max_dig=math.floor(math.log2(a_array[i+1]))
flag_1=True
ans_1=[0]
ans_2=[2<<max_dig]
SUP=10**9
for xo in next_xor:
    if ans_1[-1]^xo >= SUP:
        flag_1=False
    ans_1.append(ans_1[-1]^xo)
    ans_2.append(ans_2[-1]^xo)
print(" ".join(map(str,ans_1 if flag_1 else ans_2)))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

su = 0

for i in range(1, n):
    su ^= a[i]
    
ans = [su]

for i in range(n-1):
    su = su ^ a[i] ^ a[i+1]
    ans.append(su)
    
print(*su)

Submission status: Runtime Error

Solution code:
n = int(input())
arr = list(map(int, input().split()))
for i in arr:
  total ^= i
for i in arr:
  print(total ^ i, end=' ')

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
AA = [0] * (N)
for i in range(N):
    AA[i] = list(format(A[i], 'b'))

ans = [0] * 22
for i in range(N):
    AA[i].reverse()
    for j in range(len(AA[i])):
        ans[j] += int(AA[i][j])

ret = []
for i in range(N):
    temp = 0
    for j in range(len(AA[i])):
        if (ans[j] - int(AA[i][j])) % 2 == 1:
            temp += 1 << j

    ret.append(temp)

print(*ret)

Submission status: Runtime Error

Solution code:
from math import log
n=int(input())
arr=list(map(int,input().split()))
ma=max(arr)
c=int(log(ma,2))
for i in arr:
    d=i^(2**c-1)
    if (i&1)!=(d&1):
        d=d^1
    print(d,end=" ")

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
AA = [0] * (N)
for i in range(N):
    AA[i] = list(format(A[i], 'b'))

ans = [0] * 20
for i in range(N):
    AA[i].reverse()
    for j in range(len(AA[i])):
        ans[j] += int(AA[i][j])

ret = []
for i in range(N):
    temp = 0
    for j in range(len(AA[i])):
        if (ans[j] - int(AA[i][j])) % 2 == 1:
            temp += 1 << j

    ret.append(temp)

print(*ret)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    from functools import reduce
    assert N % 2 == 0
    b = reduce(lambda a, b: a ^ b, a)
    return [aa ^ b for aa in a]

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(*solve(N, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    from functools import reduce
    assert N % 2 == 0
    b = reduce(lambda a, b: a ^ b, a)
    return [aa ^ b for aa in a]

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(*solve(N, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Runtime Error

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))
    return " ".join(i_list)

Submission status: Runtime Error

Solution code:
n = int(input())
ns = input().split()
a = eval('^'.join(ns))
print(*[a^int(i) for i in ns])

Submission status: Runtime Error

Solution code:
 import sys

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


N = ni()
A_array = na()

A = 0

for a in A_array:
    A = A ^ a

ans_array = [A ^ a for a in A_array]

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