Problem p02975 (python)

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
a.sort()
flag = True
if len(set(a)) == 1 and a[0] == 0:
    #print('Yes')
    pass
elif N % 3 == 0:
    if len(set(a)) == 3:
        b = list(set(a))
        c = []
        for i in b:
            c.append(a.count(i))
        if a[0] != 0 and c[0] == c[1] and  c[1] == c[2] and c[2] == N//3 and b[0]^b[1]^b[2] == 0:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) and a.count(a[N-1]) == N//3*2:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    else:
        #print('No')
        flag = False
else:
    #print('No')
    flag = False
if flag:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
a.sort()
flag = True
if len(set(a)) == 1 and a[0] == 0:
    #print('Yes')
    pass
elif N % 3 == 0:
    if len(set(a)) == 3:
        b = set(a)
        c = []
        for i in list(b):
            c.append(a.count(i))
        if a[0] != 0 and c[0] == c[1] and  c[1] == c[2] and c[2] == N//3 and b[0]^b[1]^b[2] == 0:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) and a.count(a[N-1]) == N//3*2:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    else:
        #print('No')
        flag = False
else:
    #print('No')
    flag = False
if flag:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
a.sort()
flag = True
if len(set(a)) == 1 and a[0] == 0:
    #print('Yes')
    pass
elif N % 3 == 0:
    if len(set(a)) == 3:
        c = []
        for i in list(set(a)):
            c.append(a.count(i))
        if a[0] != 0 and c[0] == c[1] and  c[1] == c[2] and c[2] == N//3:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) and a.count(a[N-1]) == N//3*2:
            #print('Yes')
        else:
            #print('No')
            flag = False
    else:
        #print('No')
        flag = False
else:
    #print('No')
    flag = False
if flag:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
a.sort()
flag = True
if len(set(a)) == 1 and a[0] == 0:
    #print('Yes')
elif N % 3 == 0:
    if len(set(a)) == 3:
        c = []
        for i in list(set(a)):
            c.append(a.count(i))
        if a[0] != 0 and c[0] == c[1] and  c[1] == c[2] and c[2] == N//3:
            #print('Yes')
        else:
            #print('No')
            flag = False
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) and a.count(a[N-1]) == N//3*2:
            #print('Yes')
        else:
            #print('No')
            flag = False
    else:
        #print('No')
        flag = False
else:
    #print('No')
    flag = False
if flag:
    print('Yes')
else:
    print('No')