Problem p02914 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    A.sort(reverse=1)
    Xor=0
    l=[-1]*60
    for x in A:
        Xor^=x
    
    Xornot=Xor^(2**(A[0].bit_length())-1)

    for i in range(N):
        A[i]&=Xornot

    for x in A:
        if l[x.bit_length()-1]==-1:
            l[x.bit_length()-1]=x

    for i in range(len(l)-1,-1,-1):
        if l[i]!=-1:
            for j in range(len(l)-1,i,-1):
                if l[j]!=-1 and (l[j]>>i)&1==1:
                    l[j]^=l[i]
    f=True
    while f:
        f=False
        for x in A:
            while x.bit_length()>1:
                if l[x.bit_length()-1]!=-1:
                    x^=l[x.bit_length()-1]
                    if l[x.bit_length()-1]==-1:
                        l[x.bit_length()-1]=x         
                        f=True
                        break
                else:
                    break
        
        for i in range(len(l)-1,-1,-1):
            if l[i]!=-1:
                for j in range(len(l)-1,i,-1):
                    if l[j]!=-1 and (l[j]>>i)&1==1:
                        l[j]^=l[i]

    tmp=0
    for i in range(len(l)-1,-1,-1):
        if l[i]!=-1 and (Xor>>i)&1==0:
            tmp^=l[i]
    
    ans=tmp+(Xor^tmp)

    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    A.sort(reverse=1)
    Xor=0
    l=[-1]*A[0].bit_length()
    for x in A:
        Xor^=x
        if l[x.bit_length()-1]==-1:
            l[x.bit_length()-1]=x
    
    Xornot=Xor^(2**(A[0].bit_length())-1)

    for i in range(N):
        A[i]&=Xornot

    for x in A:
        if l[x.bit_length()-1]==-1:
            l[x.bit_length()-1]=x

    for i in range(len(l)-1,-1,-1):
        if l[i]!=-1:
            for j in range(len(l)-1,i,-1):
                if l[j]!=-1 and (l[j]>>i)&1==1:
                    l[j]^=l[i]
    f=True
    while f:
        f=False
        for x in A:
            while x.bit_length()>1:
                if l[x.bit_length()-1]!=-1:
                    x^=l[x.bit_length()-1]
                    if l[x.bit_length()-1]==-1:
                        l[x.bit_length()-1]=x         
                        f=True
                        break
                else:
                    break
        
        for i in range(len(l)-1,-1,-1):
            if l[i]!=-1:
                for j in range(len(l)-1,i,-1):
                    if l[j]!=-1 and (l[j]>>i)&1==1:
                        l[j]^=l[i]

    tmp=0
    for i in range(len(l)-1,-1,-1):
        if l[i]!=-1 and (Xor>>i)&1==0:
            tmp^=l[i]
    
    ans=tmp+(Xor^tmp)

    print(ans)

if __name__ == '__main__':
    main()