Problem:
 Score : 500 points    Problem Statement You are given two integer sequences, each of length N : a_1, ..., a_N and b_1, ..., b_N .  There are N^2 ways to choose two integers i and j such that 1 \leq i, j \leq N . For each of these N^2 pairs, we will compute a_i + b_j and write it on a sheet of paper.
That is, we will write N^2 integers in total.  Compute the XOR of these N^2 integers.   Definition of XOR  The XOR of integers c_1, c_2, ..., c_m is defined as follows:   Let the XOR be X . In the binary representation of X , the digit in the 2^k 's place ( 0 \leq k ; k is an integer) is 1 if there are an odd number of integers among c_1, c_2, ...c_m whose binary representation has 1 in the 2^k 's place, and 0 if that number is even.   For example, let us compute the XOR of 3 and 5 . The binary representation of 3 is 011 , and the binary representation of 5 is 101 , thus the XOR has the binary representation 110 , that is, the XOR is 6 .

Solution (Python):
import sys
from bisect import bisect_right,bisect_left
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  


N = I()
A,B = LI(),LI()



ans = 0
mod = 1 << 29
for i in range(29,0,-1):  
    X = [a & (mod-1) for a in A]
    Y = [b & (mod-1) for b in B]
    X.sort()
    Y.sort(reverse=True)
    mod >>= 1
    r = 0
    i1,i2,i3 = 0,0,0
    for j in range(N):
        x = X[j]
        
        
        while i1 < N and Y[i1] >= mod-x:
            i1 += 1
        while i2 < N and Y[i2] >= 2*mod-x:
            i2 += 1
        while i3 < N and Y[i3] >= 3*mod-x:
            i3 += 1
        r += i1-i2+i3
    if r % 2 == 1:
        ans += mod

print(ans)

Solution (Python):
n = int(input())













































































import numpy as np
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
ans = 0
for i in range(29):
    
    t = 1<<i
    ax = a%(2*t)
    bx = b%(2*t)
    ax.sort()
    bx.sort()
    b_num=0
    
    
    b_num =  np.searchsorted(bx, 2*t - ax)
    b_num -= np.searchsorted(bx, t - ax)
    
    
    b_num += np.searchsorted(bx, 4*t - ax)
    b_num -= np.searchsorted(bx, 3*t - ax)
    if b_num.sum()%2==1:
        ans+=1<<i
print(ans, flush=True)

Solution (Python):


import numpy as np

n = int(input())
A = np.array(list(map(int, input().split())), dtype=np.int64)
B = np.array(list(map(int, input().split())), dtype=np.int64)

ans = 0
for i in range(30):
    t = 1 << i
    C = B.copy() % (2*t)
    E = A.copy() % (2*t)
    C.sort()
    E.sort()
    D = np.searchsorted(C, 2*t-E, side="left")
    D -= np.searchsorted(C, t-E, side="left")
    D += np.searchsorted(C, 4*t-E, side="left")
    D -= np.searchsorted(C, 3*t-E, side="left")
    cnt = D.sum() % 2
    ans += cnt << i
print(ans)

Solution (Python):
from numpy import *
N = int(input())
A = int32(input().split())
B = int32(input().split())
ans = 0

for k in range(29):
  a = sort(hstack((A%(2**(k+1)),A%(2**(k+1))-2**(k+1))))
  b = B%(2**(k+1))
  ans += (sum(searchsorted(a,2**(k+1)-b)-searchsorted(a,2**k-b)))%2*2**k

print(ans)

Solution (Python):
N = int(input())
import numpy as np
A = np.array([int(x) for x in input().split()])
B = np.array([int(x) for x in input().split()])
ans = 0
for k in range(29):
    T = 2**k
    mod = 2*T
    Amod = A.copy()%mod
    Bmod = B.copy()%mod
    Bmod.sort()
    f = lambda x,y:np.searchsorted(Bmod,x-Amod)-np.searchsorted(Bmod,y-Amod)
    Cnt = f(2*T,T) + f(4*T,3*T)
    i = Cnt.sum()&1
    ans |= i << k
print(ans)

Solution (Python):
import numpy as np


def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    B = np.array(list(map(int, input().split())))
    pow_2_k = 1
    ans = 0
    for k in range(30):
        MA = A % (2 * pow_2_k)
        MB = B % (2 * pow_2_k)
        MB.sort()
        
        
        
        cnt = 0
        indices_1 = np.searchsorted(MB, pow_2_k - MA, side='left')
        indices_2 = np.searchsorted(MB, 2 * pow_2_k - MA, side='left')
        indices_3 = np.searchsorted(MB, 3 * pow_2_k - MA, side='left')
        cnt += ((N - indices_1) - (N - indices_2) + (N - indices_3)).sum()
        if cnt % 2 == 1:
            ans += pow_2_k
        pow_2_k *= 2
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())), dtype=np.int64)
B = np.array(list(map(int, input().split())), dtype=np.int64)
ans = 0
for i in range(30):
  t = 1<<i
  C = B.copy()%(2*t)
  E = A.copy()%(2*t)
  C.sort()
  E.sort()
  D = np.searchsorted(C, 2*t-E, side="left")
  D -= np.searchsorted(C, t-E, side="left")
  D += np.searchsorted(C, 4*t-E, side="left")
  D -= np.searchsorted(C, 3*t-E, side="left")
  cnt = D.sum()%2
  ans |= cnt << i
print(ans)

Solution (Python):
import numpy as np
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    A = np.array(list(map(int, input().split())))
    B = np.array(list(map(int, input().split())))
    mod = 1
    ans = 0
    for bit in range(29):
        a_mod = A % (mod*2)
        b_mod = B % (mod*2)
        b_mod.sort()
        greater_or_equal_t = np.searchsorted(b_mod, mod-a_mod)
        less_2t = np.searchsorted(b_mod, 2*mod-a_mod)
        greater_or_equal_3t = np.searchsorted(b_mod, 3*mod-a_mod)
        less_4t = np.searchsorted(b_mod, 4*mod-a_mod)
        count = (less_2t - greater_or_equal_t + less_4t - greater_or_equal_3t).sum()
        if count % 2 == 1:
            ans += mod
        mod *= 2

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=int)
B = np.array(input().split(), dtype=int)

ans = 0
mod = 1
for k in range(30):
    T = mod
    mod *= 2
    c = 0
    b = np.sort(B % mod)
    a = A % mod
    L1, R1, L2, R2 = (np.searchsorted(b, x - a).sum() for x in (T, 2*T, 3*T, 4*T))
    c += R1 - L1
    c += R2 - L2

    if c % 2:
        ans += T

print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int32)
B = np.array(input().split(), dtype=np.int32)

ans = 0
mod = 1
for k in range(30):
    T = mod
    mod *= 2
    c = 0
    b = np.sort(B % mod)
    a = A % mod
    L1, R1, L2, R2 = (np.searchsorted(b, x - a).sum() for x in (T, 2*T, 3*T, 4*T))
    c += R1 - L1
    c += R2 - L2

    if c % 2:
        ans += T

print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
bits=[[] for i in range(29)]
for i in range(29):
  mod = 2**(i+1)
  for j in b:
    bits[i].append(j%mod)
  bits[i].sort()

ans = 0
for k in range(29):
  al = []
  cnt = 0
  mod = 2**k
  for i in a:
    al.append(i%(2*mod))
  al.sort(reverse=True)
  r1 = r2 = r3 = 0
  for j in al:
    while r1 < N and bits[k][r1]+j < mod:
      r1 += 1
    while r2 < N and bits[k][r2]+j < 2*mod:
      r2 += 1
    while r3 < N and bits[k][r3]+j < 3*mod:
      r3 += 1
    cnt += N-r3+r2-r1
  ans += (cnt%2) << k
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline


n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
l = [[] for i in range(29)]
for i in range(29):
    mod = 2**(i+1)
    for j in b:
        l[i].append(j%mod)
    l[i].sort()

ans = 0
for i in range(29):
    al = []
    count = 0
    mod = 2**i
    for j in a:
        al.append(j%(2*mod))
    al.sort(reverse = True)
    r1 = r2 = r3 = 0
    for j in al:
        while r1 < n and l[i][r1]+j < mod:
            r1 += 1
        while r2 < n and l[i][r2]+j < 2*mod:
            r2 += 1
        while r3 < n and l[i][r3]+j < 3*mod:
            r3 += 1
        count += n-r3+r2-r1
    ans += (count%2) << i
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline


n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
l = [[] for i in range(29)]
for i in range(29):
    mod = 2**(i+1)
    for j in b:
        l[i].append(j%mod)
    l[i].sort()

ans = 0
for i in range(29):
    al = []
    count = 0
    mod = 2**i
    for j in a:
        al.append(j%(2*mod))
    al.sort(reverse = True)
    r1 = r2 = r3 = 0
    for j in al:
        while r1 < n and l[i][r1]+j < mod:
            r1 += 1
        while r2 < n and l[i][r2]+j < 2*mod:
            r2 += 1
        while r3 < n and l[i][r3]+j < 3*mod:
            r3 += 1
        count += n-r3+r2-r1
    ans += (count%2) << i
print(ans)

Solution (Python):
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
import bisect
con = 10 ** 9 + 7; INF = float("inf")

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


def main():
	N = int(input())
	A = getlist()
	B = getlist()
	ans = 0
	for i in range(29):
		mul = 2 ** (i + 1)
		mul2 = 2 ** i
		Aex = [A[j] % mul for j in range(N)]
		Bex = [B[j] % mul for j in range(N)]
		Aex.sort()
		Bex.sort()
		cnt = 0
		p, q, r = N - 1, N - 1, N - 1
		for j in range(N):
			var = Aex[j]
			while p >= 0 and mul2 - var <= Bex[p]:
				p -= 1
			while q >= 0 and mul - var <= Bex[q]:
				q -= 1
			while r != 0 and mul + mul2 - var <= Bex[r]:
				r -= 1
			cnt += q - p
			cnt += N - 1 - r
			
			
			
			
			
			
		
		
		
		if cnt % 2 != 0:
			ans += 2 ** i

	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = max(max(a),max(b)).bit_length()+1
a = np.array(a,dtype=np.int32)
b = np.array(b,dtype=np.int32)
ans = 0
for i in range(1,x+1):
  c = a&(1<<i)-1
  d = b&(1<<i)-1
  d.sort()
  t = 1<<(i-1)
  anstmp = 0
  t1 = np.searchsorted(d,t-c).sum()
  t2 = np.searchsorted(d,2*t-c).sum()
  t3 = np.searchsorted(d,3*t-c).sum()
  anstmp += (t2-t1)+(n-t3)
  if anstmp%2:
    ans += t
print(ans)

Solution (Python):
import numpy as np
data = int(input())
A = np.int32(input().split())
B = np.int32(input().split())

ans = 0
for k in range(29):
    a = np.sort(np.hstack((A%(2**(k+1)),A%(2**(k+1))-2**(k+1))))
    b = B%(2**(k+1))
    ans += (np.sum(np.searchsorted(a,2**(k+1)-b)-np.searchsorted(a,2**k-b)))%2*2**k

print(ans)

Solution (Python):
from numpy import *;i,p,q=int32,input,searchsorted;p();A,B,c=i(p().split()),i(p().split()),0;
for k in range(1,30):
  a=A%(1<<k);a,b=sort(hstack((a,a-2**k))),B%(1<<k);c+=(sum(q(a,2**k-b)-q(a,2**(k-1)-b)))%2<<k-1
print(c)

Solution (Python):
from numpy import *;i=int32;p=input;q=searchsorted;N=int(p());A,B,c=i(p().split()),i(p().split()),0;
for k in range(1,30):
  a=A%(1<<k);a,b=sort(hstack((a,a-2**k))),B%(1<<k);c+=(sum(q(a,2**k-b)-q(a,2**(k-1)-b)))%2<<k-1
print(c)

Solution (Python):
from numpy import *;i=int32;q=searchsorted;n,*ab=map(int,open(0).read().split());A,B,c=i(ab[:n]),i(ab[n:]),0;
for k in range(1,30):
  a,b=sort(hstack((A%(1<<k),A%(1<<k)-2**k))),B%(1<<k);c+=(sum(q(a,2**k-b)-q(a,2**(k-1)-b)))%2<<k-1
print(c)

Solution (Python):
from numpy import *;i=int32;p=input;q=searchsorted;N=int(p());A=i(p().split());B=i(p().split());c=0;
for k in range(1,30):
  a,b=sort(hstack((A%(1<<k),A%(1<<k)-2**k))),B%(1<<k);c+=(sum(q(a,2**k-b)-q(a,2**(k-1)-b)))%2<<k-1
print(c)

Solution (Python):
from numpy import *;i=int32;p=input;q=searchsorted;N=int(p());A=i(p().split());B=i(p().split());c=0;
for k in range(1,30):
  a,b=sort(hstack((A%(1<<k),A%(1<<k)-2**k))),B%(1<<k);c+=(sum(q(a,2**k-b)-q(a,2**(k-1)-b)))%2*2**(k-1)
print(c)

Solution (Python):
import numpy as n;i=n.int32;p=input;q=n.searchsorted;N=int(p());A=i(p().split());B=i(p().split());c=0;
for k in range(1,30):
  a,b=n.sort(n.hstack((A%(1<<k),A%(1<<k)-2**k))),B%(1<<k);c+=(n.sum(q(a,2**k-b)-q(a,2**(k-1)-b)))%2*2**(k-1)
print(c)

Solution (Python):
import numpy as n;i=n.int32;p=input;q=n.searchsorted;N=int(p());A=i(p().split());B=i(p().split());c=0;
for k in range(29):
  a,b=n.sort(n.hstack((A%(1<<k+1),A%(1<<k+1)-2**(k+1)))),B%(1<<k+1);c+=(n.sum(q(a,2**(k+1)-b)-q(a,2**k-b)))%2*2**k
print(c)

Solution (Python):
import numpy as n;i=n.int32;p=input;q=n.searchsorted;N=int(p());A=i(p().split());B=i(p().split());c=0;
for k in range(29):
  a,b=n.sort(n.hstack((A%(2**(k+1)),A%(2**(k+1))-2**(k+1)))),B%(2**(k+1));c+=(n.sum(q(a,2**(k+1)-b)-q(a,2**k-b)))%2*2**k
print(c)

Solution (Python):

import numpy as np
n = int(input())
a = np.array(input().split(), dtype=np.int32)
b = np.array(input().split(), dtype=np.int32)



ans = 0;mod = 1
for k in range(30):
    mod *= 2;t = mod // 2;cnt = 0
    bb = np.sort(b % mod)
    aa = a % mod
    
    
    
    l1, r1, l2, r2 = (np.searchsorted(bb, v - aa).sum() for v in (t, 2*t, 3*t, 4*t))
    cnt += r1 - l1
    cnt += r2 - l2

    if cnt % 2:
        ans += t
print(ans)

Solution (Python):
import numpy as np
n=int(input())
a=np.array(input().split(),dtype=np.int32)
b=np.array(input().split(),dtype=np.int32)
def f(t,a,b):
  power=1<<t
  mask=(power<<1)-1
  aa=a&mask
  bb=b&mask
  aa.sort()
  bb.sort()
  x1,x2,x3=(np.searchsorted(bb,v-aa).sum() for v in [power,power*2,power*3])
  zero_cnt=x1+x3-x2
  return (n-zero_cnt)%2
ans=0
for t in range(30):
  x=f(t,a,b)
  if x==1:
    ans+=1<<t
print(ans)

Solution (Python):
def solve():
    
    import sys

    N = int(input())
    A = [int(x) for x in sys.stdin.readline().split()]
    B = [int(x) for x in sys.stdin.readline().split()]
    M = max(A) + max(B)
    K = len(bin(M)) - 2
    mask = (1 << K) - 1
    k = K - 1
    T = 1 << k
    ans = 0
    while k >= 0:
        B = list(sorted(b & mask for b in B))
        A = list(sorted(a & mask for a in A))
        bit = 0
        T1, T2, T3 = 0, 0, 0
        for a in reversed(A):
            while T1 < N and a + B[T1] < T:
                T1 += 1
            while T2 < N and a + B[T2] < 2 * T:
                T2 += 1
            while T3 < N and a + B[T3] < 3 * T:
                T3 += 1
            
            
            
            
            bit += (N - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
def solve():
    
    import sys

    N = int(input())
    A = [int(x) for x in sys.stdin.readline().split()]
    B = [int(x) for x in sys.stdin.readline().split()]
    M = max(A) + max(B)
    K = len(bin(M)) - 2
    mask = (1 << K) - 1
    k = K - 1
    T = 1 << k
    ans = 0
    while k >= 0:
        for i in range(N):
            B[i] &= mask
            A[i] &= mask
        B = list(sorted(b & mask for b in B))
        A = list(sorted(a & mask for a in A))
        bit = 0
        T1, T2, T3 = 0, 0, 0
        for a in reversed(A):
            while T1 < N and a + B[T1] < T:
                T1 += 1
            while T2 < N and a + B[T2] < 2 * T:
                T2 += 1
            while T3 < N and a + B[T3] < 3 * T:
                T3 += 1
            
            
            
            
            bit += (N - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int32)
b = np.array(input().split(), dtype=np.int32)

bit = 1 << 28
mask = 2 * bit - 1
ans = 0
while bit:
    a &= mask
    b &= mask

    b.sort()

    l1, r1, l2 = (np.searchsorted(b, v - a).sum() for v in (bit, 2*bit, 3*bit))

    cnt = r1 - l1 + n - l2
    if cnt % 2:
        ans += bit

    mask >>= 1
    bit >>= 1

print(ans)

Solution (Python):
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int32)
b = np.array(input().split(), dtype=np.int32)

ans = 0
mod = 1
for k in range(30):
    mod <<= 1
    t = mod >> 1
    bb = np.sort(b % mod)
    aa = a % mod
    l1, r1, l2, r2 = (np.searchsorted(bb, v - aa).sum() for v in (t, 2*t, 3*t, 4*t))
    cnt = r1 - l1 + r2 - l2

    if cnt % 2:
        ans += t

print(ans)

Solution (Python):
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int32)
b = np.array(input().split(), dtype=np.int32)

ans = 0
mod = 1
for k in range(30):
    mod *= 2
    t = mod // 2
    cnt = 0
    bb = np.sort(b % mod)
    aa = a % mod
    l1, r1, l2, r2 = (np.searchsorted(bb, v - aa).sum() for v in (t, 2*t, 3*t, 4*t))
    cnt += r1 - l1
    cnt += r2 - l2

    if cnt % 2:
        ans += t

print(ans)

Solution (Python):
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())), dtype=np.int32)
b = np.array(list(map(int, input().split())), dtype=np.int32)

ans = 0
mod = 1
for k in range(30):
    mod *= 2
    t = mod // 2
    cnt = 0
    bb = np.sort(b % mod)
    aa = a % mod
    l1, r1, l2, r2 = (np.searchsorted(bb, v - aa).sum() for v in (t, 2*t, 3*t, 4*t))
    cnt += r1 - l1
    cnt += r2 - l2

    if cnt % 2:
        ans += t

print(ans)

Solution (Python):
import numpy as np

n = int(input())
A = np.array(input().split(), np.int64)
B = np.array(input().split(), np.int64)

A = np.sort(A)
B = np.sort(B)

C = [0]*30
for k in range(30):
    A_ = A%(2**(k+1))
    B_ = B%(2**(k+1))
    A_ = np.sort(A_)
    B_ = np.sort(B_)
    A0 = A_[A_<=2**k]
    A1 = A_[A_>2**k]
    C[k] += (np.searchsorted(B_, 2**(k+1)-A0, side='left')-np.searchsorted(B_, 2**k-A0, side='left')).sum()
    C[k] += (np.searchsorted(B_, 2**(k+1)-A1, side='left')-np.searchsorted(B_, 0, side='left')).sum()
    C[k] += (np.searchsorted(B_, 2**(k+1), side='left')-np.searchsorted(B_, 2**(k+1)+2**k-A1, side='left')).sum()

ans = 0
for i in range(len(C)):
    if C[i]%2 == 1:
        ans += 2**i

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from bisect import bisect_left

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


L = 30
ans = 0
for l in range(L):
    P = []
    g = 1<<l
    g2 = 1<<(1+l)
    B1 = []
    B2 = []
    for b in B:
        if b&g:
            B1.append(b)
        else:
            B2.append(b)
    B = B2 + B1

    A1 = []
    A2 = []
    for a in A:
        if a&g:
            A1.append(a)
        else:
            A2.append(a)
    A = A1 + A2

    count = 0
    ind1 = 0
    ind2 = 0
    ind3 = 0
    for a in A:
        while ind1 < N and B[ind1]%g2 + a%g2 < g:
            ind1 += 1
        while ind2 < N and B[ind2]%g2 + a%g2 < 2*g:
            ind2 += 1
        while ind3 < N and B[ind3]%g2 + a%g2 < 3*g:
            ind3 += 1
        count += ind2 - ind1 + N - ind3
    if count%2 == 1:
        ans += g
print(ans)

Solution (Python):
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)






N = int(input())

A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)


mask = 1

ans = 0
for i in range(29):
    NA = A & mask
    NB = B & mask
    NA.sort()
    NB.sort()

    T = 2 ** i
    x1, x2, x3 = [np.searchsorted(NB, t - NA).sum() for t in [T, 2 * T, 3 * T]]
    zero_cnt = x1 + (x3 - x2)
    if (N*N - zero_cnt) % 2 == 1:
        ans += 2 ** i

    mask = mask * 2 + 1

print(ans)

Solution (Python):
import numpy as np
N = int(input())

a = np.array(list(map(int,input().split())))
b = np.array(list(map(int,input().split())))

carries = [0]*30
for i in range(1,30):
    thres = pow(2,i)
    ra = np.sort(thres - (a % thres))
    rb = np.sort(b % thres)
    
    r = np.sum(N-np.searchsorted(rb,ra))
    carries[i] = r

ans = 0
i = 0
for i in range(30):
    a1 = np.sum(a % 2)
    a0 = N - a1
    b1 = np.sum(b % 2)
    b0 = N - b1
    ans += ((a1*b0 + a0*b1 + carries[i]) % 2) << i
    a //= 2
    b //= 2

print(ans)

Solution (Python):
from numpy import int32, searchsorted

N, *AB = map(int, open(0).read().split())
A, B = int32(AB[:N]), int32(AB[N:])

state = 1 << 28
mask = 2 * state - 1
ans = 0
while state:
    A &= mask
    B &= mask
    A.sort()
    B.sort()

    a, b, c = (searchsorted(B, i * state - A).sum() for i in range(1, 4))
    M = a + (c - b)
    if (N - M) % 2 == 1:
        ans += state

    state >>= 1
    mask >>= 1

print(ans)

Solution (Python):
def d_two_sequences():
    
    import numpy as np
    N = int(input())
    A = np.array(input().split(), dtype=np.int32)
    B = np.array(input().split(), dtype=np.int32)

    bit = 1 << 28  
    ans = 0
    while bit:
        
        mask = 2 * bit - 1
        A &= mask
        B &= mask
        A.sort()
        B.sort()

        
        x1, x2, x3 = (np.searchsorted(B, v - A).sum() for v in [bit, 2 * bit, 3 * bit])
        
        
        zero_cnt = x1 + (x3 - x2)
        if (N - zero_cnt) % 2:
            ans += bit  
        bit >>= 1  
    return ans

print(d_two_sequences())

Solution (Python):
import numpy as np
N = int(input())
A = np.array(input().split(), dtype = np.int32)
B = np.array(input().split(), dtype = np.int32)
ans = 0
for i in range(29)[::-1]:
    res = 0
    p = 1<<i
    A&=(p*2-1)
    B&=(p*2-1)
    B.sort()
    i, j, k = [np.searchsorted(B, t-A).sum() for t in [p, p*2, p*3]]
    res = (i+k-j)
    if (N-res)%2:
        ans+=p
print(ans)

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

a.sort()
b.sort()
ans=0

for i in range(29):
    c=[]
    d=[]
    T=2**i
    for u in a:
        c.append(u%(2**(i+1)))
    for u in b:
        d.append(u%(2**(i+1)))
    c.sort(reverse=True)
    d.sort()
    
    left=0
    mid=0
    right=0
    
    count=0
    
    for u in c:
        
        m_left=T-u
        m_mid=2*T-u
        m_right=3*T-u
        
        while left<n:
            if d[left]<m_left:
                left+=1
            else:
                break
        while mid<n:
            if d[mid]<m_mid:
                mid+=1
            else:
                break
        while right<n:
            if d[right]<m_right:
                right+=1
            else:
                break
                
    
        count+=mid-left+n-right

    if count%2==1:
        ans+=2**i
    
print(ans)

Solution (Python):
from bisect import bisect_right as br
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
s, t = 0, 0
for i in range(N):
    s ^= A[i]
    t ^= B[i]
ans = (s ^ t) * (N % 2)
for k in range(1, 29):
    m = (1<<k)
    AA = sorted([a % m for a in A])
    BB = sorted([a % m for a in B])[::-1]
    i, j = 0, 0
    while i < N and AA[i] + BB[j] < m:
        i += 1
    s = 0
    while i < N:
        while j < N and AA[i] + BB[j] >= m:
            j += 1
        s += j
        i += 1
    ans ^= (s % 2) << k
print(ans)

Solution (Python):
from bisect import bisect_right as br
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
s, t = 0, 0
for i in range(N):
    s ^= A[i]
    t ^= B[i]
ans = (s ^ t) * (N % 2)
for k in range(1, 29):
    m = (1<<k) - 1
    AA = sorted([a & m for a in A])
    BB = sorted([a & m for a in B])[::-1]
    m += 1
    i, j = 0, 0
    while i < N and AA[i] + BB[j] < m:
        i += 1
    s = 0
    while i < N:
        while j < N and AA[i] + BB[j] >= m:
            j += 1
        s += j
        i += 1
    ans ^= (s % 2) << k
print(ans)

Solution (Python):
def examD():
    N = I()
    a = LI();  b = LI()
    cura = [0]*N; curb=[0]*N
    ans = 0
    for i in range(28,-1,-1):
        T = (2 ** i)
        for j in range(N):
            cura[j] = a[j]%(2**(i+1))
            curb[j] = b[j]%(2**(i+1))
        curb.sort()
        cura.sort(reverse=1)
        f, l1, r1, l2 = 0, 0, 0, 0
        for x in cura:
            while l1 < N and x + curb[l1] < T:
                l1 += 1
            while r1 < N and x + curb[r1] < 2 * T:
                r1 += 1
            while l2 < N and x + curb[l2] < 3 * T:
                l2 += 1
            f += N - l2 + r1 - l1
        ans += T * (f & 1)
    print(ans)

import sys,copy,bisect,itertools,heapq,math
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 S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]

from bisect import bisect_left


ans = 0

for k in range(29):
    a0 = []
    a1 = []
    a0a = a0.append
    a1a = a1.append
    
    b0 = []
    b1 = []
    b0a = b0.append
    b1a = b1.append
    for i in a: 
        if i&(1<<k): a1a(i)
        else: a0a(i)
    for i in b: 
        if i&(1<<k): b1a(i)
        else: b0a(i)
    
    a = a0+a1
    b = b0+b1
    mask = (1<<(k+1))-1
    
    aa = [i&mask for i in a]
    bb = [i&mask for i in b]
    
    res = 0
    p1 = 1<<k
    p2 = mask+1
    p3 = p1+p2

    j1=j2=j3=0    
    for ai in reversed(aa):
        while j1 < n and ai+bb[j1] < p1:
            j1 += 1
        while j2 < n and ai+bb[j2] < p2:
            j2 += 1
        while j3 < n and ai+bb[j3] < p3:
            j3 += 1
        res += j2-j1+n-j3
        
        
    ans |= (res&1)<<k
    



print(ans)

Solution (Python):
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    aa = np.array(input().split(), dtype="i8")
    bb = np.array(input().split(), dtype="i8")
    ans = 0
    for k in range(29):
        t = 1 << k
        t2 = t << 1
        am = aa % t2
        bm = bb % t2
        
        bm.sort()
        
        
        cnt = n % 2
        cnt += sum(np.sum(np.searchsorted(bm, tk - am)) for tk in range(t, t * 4, t))
        if cnt % 2:
            ans += t
    print(ans)

main()

Solution (Python):
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    aa = np.array(list(map(int, input().split())), dtype="i8")
    bb = np.array(list(map(int, input().split())), dtype="i8")
    ans = 0
    for k in range(29):
        t = 1 << k
        t2 = t << 1
        am = aa % t2
        bm = bb % t2
        
        bm.sort()
        
        
        cnt = n % 2
        for tk in range(t, t * 4, t):
            cnt += np.sum(np.searchsorted(bm, tk - am))
        if cnt % 2:
            ans += t
    print(ans)

main()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007


def A():
    a, b, c = LI()
    if a + b >= c:
        print("Yes")
    else:
        print("No")
    return


def B():
    n = II()
    s = SR(n)
    m = II()
    t = SR(m)
    ans = 0
    for si in s:
        ans = max(ans, s.count(si) - t.count(si))
    print(ans)
    return


def C():
    n = II()
    ab = LIR(n)
    cd = LIR(n)
    ab.sort()
    cd.sort()
    check = [0 for i in range(n)]
    ans = 0
    for _, c in enumerate(cd):
        d = c[1]
        c = c[0]
        maxy = -1
        x = -1
        for k, a in enumerate(ab):
            b = a[1]
            a = a[0]
            if maxy < b and c > a and check[k] == 0 and d > b:
                maxy = b
                x = k
        if x != -1:
            ans += 1
            check[x] += 1
    print(ans)


    return


def D():
    N = II()
    a = LI()
    b = LI()
    ans = 0
    t = 1
    for i in range(29):
        a2 = [A & ((t << 1) - 1) for A in a]
        b2 = [B & ((t << 1) - 1) for B in b]
        a2.sort(reverse=True)
        b2.sort()
        ansb, r1, r2, r3 = 0, 0, 0, 0
        for A in a2:
            while r1 < N and A + b2[r1] < t:
                r1 += 1
            while r2 < N and A + b2[r2] < 2*t:
                r2 += 1
            while r3 < N and A + b2[r3] < 3*t:
                r3 += 1
            ansb += r2 ^ r1 ^ N ^ r3
            ansb = ansb & 1
        ans += (ansb << i)
        t = t << 1
    print(ans)
    return


if __name__ == '__main__':
    D()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007


def A():
    a, b, c = LI()
    if a + b >= c:
        print("Yes")
    else:
        print("No")
    return


def B():
    n = II()
    s = SR(n)
    m = II()
    t = SR(m)
    ans = 0
    for si in s:
        ans = max(ans, s.count(si) - t.count(si))
    print(ans)
    return


def C():
    n = II()
    ab = LIR(n)
    cd = LIR(n)
    ab.sort()
    cd.sort()
    check = [0 for i in range(n)]
    ans = 0
    for _, c in enumerate(cd):
        d = c[1]
        c = c[0]
        maxy = -1
        x = -1
        for k, a in enumerate(ab):
            b = a[1]
            a = a[0]
            if maxy < b and c > a and check[k] == 0 and d > b:
                maxy = b
                x = k
        if x != -1:
            ans += 1
            check[x] += 1
    print(ans)


    return


def D():
    N = II()
    a = LI()
    b = LI()
    ans = 0
    t = 1
    for i in range(29):
        a2 = [A & ((t << 1) - 1) for A in a]
        b2 = [B & ((t << 1) - 1) for B in b]
        a2.sort(reverse=True)
        b2.sort()
        ansb = r1 = r2 = r3 = 0
        for A in a2:
            while r1 < N and A + b2[r1] < t:
                r1 += 1
            while r2 < N and A + b2[r2] < 2*t:
                r2 += 1
            while r3 < N and A + b2[r3] < 3*t:
                r3 += 1
            ansb += r2 ^ r1 ^ N ^ r3
            ansb = ansb & 1
        ans += (ansb << i)
        t = t << 1
    print(ans)
    return


if __name__ == '__main__':
    D()