Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    maxD = 30

    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    ans = 0
    for d in range(maxD):
        m1 = 1 << d
        mask = m1 - 1
        B0s, B1s = [], []
        for B in Bs:
            if B & m1:
                B1s.append(B & mask)
            else:
                B0s.append(B & mask)
        B0s.sort()
        B1s.sort()
        lenB0, lenB1 = len(B0s), len(B1s)

        A2s = [(A & mask, A & m1) for A in As]
        A2s.sort()

        num1 = 0
        iB0, iB1 = lenB0, lenB1
        for A2, v in A2s:
            while iB0 > 0 and B0s[iB0-1] >= m1-A2:
                iB0 -= 1
            while iB1 > 0 and B1s[iB1-1] >= m1-A2:
                iB1 -= 1
            if v:
                num1 += iB0
                num1 += lenB1 - iB1
            else:
                num1 += lenB0 - iB0
                num1 += iB1

        if num1 % 2:
            ans |= m1

    print(ans)


solve()


Fixed submission:
from bisect import bisect_left, bisect_right

def solve():
    maxD = 30

    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    As.sort()
    Bs.sort()

    ans = 0
    for d in reversed(range(maxD)):
        m1 = 1 << d

        iA = bisect_left(As, m1)
        iB = bisect_left(Bs, m1)

        num1 = N * (N-iA + N-iB)

        As = As[:iA] + [A-m1 for A in As[iA:]]
        Bs = Bs[:iB] + [B-m1 for B in Bs[iB:]]

        As.sort()
        Bs.sort(reverse=True)

        iB = 0
        for A in As:
            while iB < N and A + Bs[iB] >= m1:
                iB += 1
            num1 += iB

        Bs.reverse()

        if num1 % 2:
            ans |= m1

    print(ans)


solve()

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    maxD = 30

    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    ans = 0
    for d in range(maxD):
        m1 = 1 << d
        mask = m1 - 1
        B0s, B1s = [], []
        for B in Bs:
            if B & m1:
                B1s.append(B & mask)
            else:
                B0s.append(B & mask)
        B0s.sort()
        B1s.sort()
        lenB0, lenB1 = len(B0s), len(B1s)

        A2s = [(A & mask, A & m1) for A in As]
        A2s.sort()

        num1 = 0
        iB0, iB1 = lenB0, lenB1
        for A2, v in A2s:
            while iB0 > 0 and B0s[iB0-1] >= m1-A2:
                iB0 -= 1
            while iB1 > 0 and B1s[iB1-1] >= m1-A2:
                iB1 -= 1
            if v:
                num1 += iB0
                num1 += lenB1 - iB1
            else:
                num1 += lenB0 - iB0
                num1 += iB1

        if num1 % 2:
            ans |= m1

    print(ans)


solve()


Fixed submission:
from bisect import bisect_left, bisect_right

def solve():
    maxD = 30

    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    As.sort()
    Bs.sort()

    ans = 0
    for d in reversed(range(maxD)):
        m1 = 1 << d

        iA = bisect_left(As, m1)
        iB = bisect_left(Bs, m1)

        num1 = N * (N-iA + N-iB)

        As = As[:iA] + [A-m1 for A in As[iA:]]
        Bs = Bs[:iB] + [B-m1 for B in Bs[iB:]]

        As.sort()
        Bs.sort(reverse=True)

        iB = 0
        for A in As:
            while iB < N and A + Bs[iB] >= m1:
                iB += 1
            num1 += iB

        Bs.reverse()

        if num1 % 2:
            ans |= m1

    print(ans)


solve()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right

maxD = 30

N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

ans = 0
for d in range(maxD):
    m1 = 1 << d
    mask = m1 - 1
    B0s, B1s = [], []
    for B in Bs:
        if B & m1:
            B1s.append(B & mask)
        else:
            B0s.append(B & mask)
    B0s.sort()
    B1s.sort()
    lenB0, lenB1 = len(B0s), len(B1s)

    num1 = 0
    for A in As:
        A2 = A & mask
        if A & m1:
            i = bisect_left(B0s, m1-A2)
            num1 += i
            i = bisect_left(B1s, m1-A2)
            num1 += lenB1 - i
        else:
            i = bisect_left(B0s, m1-A2)
            num1 += lenB0 - i
            i = bisect_left(B1s, m1-A2)
            num1 += i

    if num1 % 2:
        ans |= m1

print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right

def solve():
    maxD = 30

    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    As.sort()
    Bs.sort()

    ans = 0
    for d in reversed(range(maxD)):
        m1 = 1 << d

        iA = bisect_left(As, m1)
        iB = bisect_left(Bs, m1)

        num1 = N * (N-iA + N-iB)

        As = As[:iA] + [A-m1 for A in As[iA:]]
        Bs = Bs[:iB] + [B-m1 for B in Bs[iB:]]

        As.sort()
        Bs.sort(reverse=True)

        iB = 0
        for A in As:
            while iB < N and A + Bs[iB] >= m1:
                iB += 1
            num1 += iB

        Bs.reverse()

        if num1 % 2:
            ans |= m1

    print(ans)


solve()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right

maxD = 30

N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

ans = 0
for d in range(maxD):
    m1 = 1 << d
    mask = m1 - 1
    B0s, B1s = [], []
    for B in Bs:
        if B & m1:
            B1s.append(B & mask)
        else:
            B0s.append(B & mask)
    B0s.sort()
    B1s.sort()
    lenB0, lenB1 = len(B0s), len(B1s)

    num1 = 0
    for A in As:
        A2 = A & mask
        if A & m1:
            i = bisect_left(B0s, m1-A2)
            num1 += i
            i = bisect_left(B1s, m1-A2)
            num1 += lenB1 - i
        else:
            i = bisect_left(B0s, m1-A2)
            num1 += lenB0 - i
            i = bisect_left(B1s, m1-A2)
            num1 += i

    if num1 % 2:
        ans |= m1

print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right

def solve():
    maxD = 30

    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    As.sort()
    Bs.sort()

    ans = 0
    for d in reversed(range(maxD)):
        m1 = 1 << d

        iA = bisect_left(As, m1)
        iB = bisect_left(Bs, m1)

        num1 = N * (N-iA + N-iB)

        As = As[:iA] + [A-m1 for A in As[iA:]]
        Bs = Bs[:iB] + [B-m1 for B in Bs[iB:]]

        As.sort()
        Bs.sort(reverse=True)

        iB = 0
        for A in As:
            while iB < N and A + Bs[iB] >= m1:
                iB += 1
            num1 += iB

        Bs.reverse()

        if num1 % 2:
            ans |= m1

    print(ans)


solve()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

ans = 0
MOD = 1 << 29
T = 1 << 28
for k in range(29)[::-1]:
    ans <<= 1
    As = list(map(lambda x: x % MOD, As))
    Bs = list(map(lambda x: x % MOD, Bs))
    Bs.sort()

    num1 = 0
    for A in As:
        iT = bisect_left(Bs, T - A)
        i2T = bisect_left(Bs, 2 * T - A)
        i3T = bisect_left(Bs, 3 * T - A)
        i4T = bisect_left(Bs, 4 * T - A)
        num1 += (i2T - iT) + (i4T - i3T)

    if num1 % 2 == 1:
        ans += 1

    MOD >>= 1
    T >>= 1

print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right

def solve():
    maxD = 30

    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    As.sort()
    Bs.sort()

    ans = 0
    for d in reversed(range(maxD)):
        m1 = 1 << d

        iA = bisect_left(As, m1)
        iB = bisect_left(Bs, m1)

        num1 = N * (N-iA + N-iB)

        As = As[:iA] + [A-m1 for A in As[iA:]]
        Bs = Bs[:iB] + [B-m1 for B in Bs[iB:]]

        As.sort()
        Bs.sort(reverse=True)

        iB = 0
        for A in As:
            while iB < N and A + Bs[iB] >= m1:
                iB += 1
            num1 += iB

        Bs.reverse()

        if num1 % 2:
            ans |= m1

    print(ans)


solve()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

ans = 0
MOD = 1 << 29
T = 1 << 28
for k in range(29)[::-1]:
    ans <<= 1
    As = list(map(lambda x: x % MOD, As))
    Bs = list(map(lambda x: x % MOD, Bs))
    Bs.sort()

    num1 = 0
    for A in As:
        iT = bisect_left(Bs, T - A)
        i2T = bisect_left(Bs, 2 * T - A)
        i3T = bisect_left(Bs, 3 * T - A)
        i4T = bisect_left(Bs, 4 * T - A)
        num1 += (i2T - iT) + (i4T - i3T)

    if num1 % 2 == 1:
        ans += 1

    MOD >>= 1
    T >>= 1

print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right

def solve():
    maxD = 30

    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    As.sort()
    Bs.sort()

    ans = 0
    for d in reversed(range(maxD)):
        m1 = 1 << d

        iA = bisect_left(As, m1)
        iB = bisect_left(Bs, m1)

        num1 = N * (N-iA + N-iB)

        As = As[:iA] + [A-m1 for A in As[iA:]]
        Bs = Bs[:iB] + [B-m1 for B in Bs[iB:]]

        As.sort()
        Bs.sort(reverse=True)

        iB = 0
        for A in As:
            while iB < N and A + Bs[iB] >= m1:
                iB += 1
            num1 += iB

        Bs.reverse()

        if num1 % 2:
            ans |= m1

    print(ans)


solve()