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

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().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.sort()
        A.sort(reverse=True)
        bit = 0
        T1, T2, T3, T4 = 0, 0, 0, 0
        for a in A:
            T1 = bisect_left(B, T - a, T1)
            T2 = bisect_left(B, 2 * T - a, T2)
            T3 = bisect_left(B, 3 * T - a, T3)
            T4 = bisect_left(B, 4 * T - a, T4)
            bit += (T4 - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    # from bisect import bisect_left
    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
            # T1 = bisect_left(B, T - a, T1)
            # T2 = bisect_left(B, 2 * T - a, T2)
            # T3 = bisect_left(B, 3 * T - a, T3)
            # T4 = bisect_left(B, 4 * T - a, T4)
            bit += (N - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Runtime Error):
def solve():
    from bisect import bisect_left

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().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.sort()
        A.sort(revese=True)
        bit = 0
        T1, T2, T3, T4 = 0, 0, 0, 0
        for a in A:
            T1 = bisect_left(B, T - a, T1)
            T2 = bisect_left(B, 2 * T - a, T2)
            T3 = bisect_left(B, 3 * T - a, T3)
            T4 = bisect_left(B, 4 * T - a, T4)
            bit += (T4 - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    # from bisect import bisect_left
    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
            # T1 = bisect_left(B, T - a, T1)
            # T2 = bisect_left(B, 2 * T - a, T2)
            # T3 = bisect_left(B, 3 * T - a, T3)
            # T4 = bisect_left(B, 4 * T - a, T4)
            bit += (N - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()

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

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().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.sort()
        A.sort(reverse=True)
        bit = 0
        T1, T2, T3, T4 = 0, 0, 0, 0
        for a in A:
            T1 = bisect_left(B, T - a, T1)
            T2 = bisect_left(B, 2 * T - a, T2)
            T3 = bisect_left(B, 3 * T - a, T3)
            T4 = bisect_left(B, 4 * T - a, T4)
            bit += (T4 - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    # from bisect import bisect_left
    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
            # T1 = bisect_left(B, T - a, T1)
            # T2 = bisect_left(B, 2 * T - a, T2)
            # T3 = bisect_left(B, 3 * T - a, T3)
            # T4 = bisect_left(B, 4 * T - a, T4)
            bit += (N - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()

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

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().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
        B.sort()
        bit = 0
        for a in A:
            a_ = a & mask
            T1 = bisect_left(B, T - a_)
            T2 = bisect_left(B, 2 * T - a_, T1)
            T3 = bisect_left(B, 3 * T - a_, T2)
            T4 = bisect_left(B, 4 * T - a_, T3)
            bit += (T4 - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    # from bisect import bisect_left
    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
            # T1 = bisect_left(B, T - a, T1)
            # T2 = bisect_left(B, 2 * T - a, T2)
            # T3 = bisect_left(B, 3 * T - a, T3)
            # T4 = bisect_left(B, 4 * T - a, T4)
            bit += (N - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()

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

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().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
        B.sort()
        bit = 0
        for a in A:
            a_ = a & mask
            T1 = bisect_left(B, T - a_)
            T2 = bisect_left(B, 2 * T - a_)
            T3 = bisect_left(B, 3 * T - a_)
            T4 = bisect_left(B, 4 * T - a_)
            bit += (T4 - T3) + (T2 - T1)
            bit &= 1
        ans += bit * (1 << k)
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    # from bisect import bisect_left
    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
            # T1 = bisect_left(B, T - a, T1)
            # T2 = bisect_left(B, 2 * T - a, T2)
            # T3 = bisect_left(B, 3 * T - a, T3)
            # T4 = bisect_left(B, 4 * T - a, T4)
            bit += (N - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()

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

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    M = max(A) + max(B)
    K = len(bin(M)) - 2
    mask = 1 << K
    k = K - 1
    T = 1 << k
    ans = 0
    while k >= 0:
        B = [x % mask for x in B]
        B.sort()
        bit = 0
        for a in A:
            a_ = a % mask
            T1 = bisect_left(B, T - a_)
            T2 = bisect_left(B, 2 * T - a_)
            T3 = bisect_left(B, 3 * T - a_)
            T4 = bisect_left(B, 4 * T - a_)
            bit += (T4 - T3) + (T2 - T1)
            bit &= 1
        ans += bit * (1 << k)
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    # from bisect import bisect_left
    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
            # T1 = bisect_left(B, T - a, T1)
            # T2 = bisect_left(B, 2 * T - a, T2)
            # T3 = bisect_left(B, 3 * T - a, T3)
            # T4 = bisect_left(B, 4 * T - a, T4)
            bit += (N - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()

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

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().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 = [x & mask for x in B]
        B.sort()
        bit = 0
        for a in A:
            a_ = a & mask
            T1 = bisect_left(B, T - a_)
            T2 = bisect_left(B, 2 * T - a_)
            T3 = bisect_left(B, 3 * T - a_)
            T4 = bisect_left(B, 4 * T - a_)
            bit += (T4 - T3) + (T2 - T1)
            bit &= 1
        ans += bit * (1 << k)
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    # from bisect import bisect_left
    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
            # T1 = bisect_left(B, T - a, T1)
            # T2 = bisect_left(B, 2 * T - a, T2)
            # T3 = bisect_left(B, 3 * T - a, T3)
            # T4 = bisect_left(B, 4 * T - a, T4)
            bit += (N - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()

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


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().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 = [x & mask for x in B]
    B.sort()
    bit = 0
    for a in A:
        a_ = a & mask
        T1 = bisect_left(B, T - a_)
        T2 = bisect_left(B, 2 * T - a_)
        T3 = bisect_left(B, 3 * T - a_)
        T4 = bisect_left(B, 4 * T - a_)
        bit += (T4 - T3) + (T2 - T1)
        bit &= 1
    ans += bit * (1 << k)
    k -= 1
    T >>= 1
    mask >>= 1

print(ans)


Fixed submission:
def solve():
    # from bisect import bisect_left
    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
            # T1 = bisect_left(B, T - a, T1)
            # T2 = bisect_left(B, 2 * T - a, T2)
            # T3 = bisect_left(B, 3 * T - a, T3)
            # T4 = bisect_left(B, 4 * T - a, T4)
            bit += (N - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()

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

# def lower_bound(L, v):
#     # [ok, ng) - Maximum
#     # (ng, ok] - Minimum
#     # ok が 最終的な答え
#     ok = N
#     ng = -1
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if L[mid] >= v:
#             ok = mid
#         else:
#             ng = mid
#     return ok


# def upper_bound(L, v):
#     # [ok, ng) - Maximum
#     # (ng, ok] - Minimum
#     # ok が 最終的な答え
#     ok = -1
#     ng = N
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if L[mid] < v:
#             ok = mid
#         else:
#             ng = mid
#     return ok


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort()
B.sort()
M = A[-1] + B[-1]
K = len(bin(M)) - 2
mask = (1 << K) - 1
bit = [0] * K
k = K - 1
while M > 0:
    T = 1 << k
    B = [x & mask for x in B]
    B.sort()
    for a in A:
        a_ = a & mask
        T1 = bisect_left(B, T - a_)
        T2 = bisect_left(B, 2 * T - a_)
        T3 = bisect_left(B, 3 * T - a_)
        T4 = bisect_left(B, 4 * T - a_)
        bit[k] += (T4 - T3) + (T2 - T1)
        bit[k] %= 2
    M >>= 1
    k -= 1
    mask >>= 1

result = 0
for i, k in enumerate(bit):
    result += k * (1 << i)

print(result)


Fixed submission:
def solve():
    # from bisect import bisect_left
    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
            # T1 = bisect_left(B, T - a, T1)
            # T2 = bisect_left(B, 2 * T - a, T2)
            # T3 = bisect_left(B, 3 * T - a, T3)
            # T4 = bisect_left(B, 4 * T - a, T4)
            bit += (N - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()