Problem p03412 (python)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = 29
val = 0

def lcount(a,b,x):
    """ソート済a,bに対して, a[i]+b[j]<=xなるi,jの個数
    """
    la = len(a)
    lb = len(b)
    j = -1
    ans = 0
    for i in range(la-1, -1, -1):
        while j+1<lb and a[i]+b[j+1]<=x:
            j += 1
        ans += (j+1)
    return ans
for k in range(l):
    # i桁目を求める
    tmp = pow(2, k+1)
    bb = [item%(tmp) for item in b]
    aa = [item%(tmp) for item in a]
    aa.sort()
    bb.sort()
    ans = n**2 - lcount(aa,bb,tmp//2*3-1) + lcount(aa,bb,tmp-1) - lcount(aa,bb,tmp//2-1)
    if ans%2:
        val += pow(2, k)
print(val)

Buggy submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    l = 29
    val = 0
    from bisect import bisect_left as bll, bisect_right as brr
    def bl(bb, ind):
        if ind in dl:
            return dl[inte]
        else:
            tt = bll(bb, ind)
            dl[ind] = tt
            return tt
    def br(bb, ind):
        if ind in dr:
            return dr[inte]
        else:
            tt = brr(bb, ind)
            dr[ind] = tt
            return tt  

    for k in range(l):
        # i桁目を求める
        tmp = pow(2, k+1)
        bb = [item%(tmp) for item in b]
        bb.sort()
        ans = 0
        dl = {}
        dr = {}
        for item in a:
            aa = item%tmp
            if aa<=tmp//2:
                ans += (br(bb, tmp-1-aa) - bl(bb, tmp//2-aa))%2
            else:
                ans += (br(bb, tmp-1-aa) + (n - bl(bb, tmp//2*3-aa)))%2
        if ans%2:
            val += pow(2, k)
    print(val)
main()

Buggy submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    l = 29
    val = 0
    from bisect import bisect_left as bll, bisect_right as brr
    def bl(bb, ind):
        if ind in dl:
            return dl[inte]
        else:
            tmp = bll(bb, ind)
            dl[ind] = tmp
            return tmp
    def br(bb, ind):
        if ind in dr:
            return dr[inte]
        else:
            tmp = brr(bb, ind)
            dr[ind] = tmp
            return tmp    

    for k in range(l):
        # i桁目を求める
        tmp = pow(2, k+1)
        bb = [item%(tmp) for item in b]
        bb.sort()
        ans = 0
        dl = {}
        dr = {}
        for item in a:
            aa = item%tmp
            if aa<=tmp//2:
                ans += (br(bb, tmp-1-aa) - bl(bb, tmp//2-aa))%2
            else:
                ans += (br(bb, tmp-1-aa) + (n - bl(bb, tmp//2*3-aa)))%2
        if ans%2:
            val += pow(2, k)
    print(val)
main()