Problem:


Score : 300 points

Problem Statement

Snuke has N hats. The i-th hat has an integer a_i written on it.

There are N camels standing in a circle.
Snuke will put one of his hats on each of these camels.

If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print Yes; otherwise, print No.

The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself.

What is XOR?

The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non-negative integers x_1, x_2, \ldots, x_n is defined as follows:

- When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.

For example, 3 \oplus 5 = 6.

Constraints

All values in input are integers.

3 \leq N \leq 10^{5}

0 \leq a_i \leq 10^{9}

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_{N}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

Yes

If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is Yes.

Sample Input 2

4
1 2 4 8

Sample Output 2

No

There is no such way to distribute the hats; the answer is No.



Sample input:
3
1 2 3


Sample output:
Yes

Submission status: Runtime Error

Solution code:
N = int(input())
*A, = map(int,input().split())

if N%3:
    ans = True
    for a in A:
        if a:ans=False;break
else:
    B = set(A)
    l = len(B)
    ans = True
    if l>3:
        ans = False
    elif l==2:
        ans = False
        1/0
    elif l==1:
        for b in B:
            if b:ans=False;break
    else:
        a,b,c = B
        ans = ans and (A.count(a)==A.count(b)==A.count(c)==N//3) and (a^b==c)
        
if ans:print("Yes")
else:print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
*A, = map(int,input().split())

if N%3:
    ans = True
    for a in A:
        if a:ans=False;break
else:
    B = set(A)
    l = len(B)
    ans = True
    if l>3:
        ans = False
        1/0
    elif l==2:
        ans = False
    elif l==1:
        for b in B:
            if b:ans=False;break
    else:
        a,b,c = B
        ans = ans and (A.count(a)==A.count(b)==A.count(c)==N//3) and (a^b==c)
        
if ans:print("Yes")
else:print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
*A, = map(int,input().split())

if N%3:
    ans = True
    for a in A:
        if a:ans=False;break
else:
    B = set(A)
    l = len(B)
    ans = True
    if l>3 or l==2:
        ans = False
        1/0
    elif l==1:
        for b in B:
            if b:ans=False;break
    else:
        a,b,c = B
        ans = ans and (A.count(a)==A.count(b)==A.count(c)==N//3) and (a^b==c)
        
if ans:print("Yes")
else:print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
*A, = map(int,input().split())

if N%3:
    ans = True
    for a in A:
        if a:ans=False;break
else:
    B = set(A)
    l = len(B)
    ans = True
    if l>3 or l==2:ans = False
    elif l==1:
        for b in B:
            if b:ans=False;break
    else:
        a,b,c = B
        ans = ans and (A.count(a)==A.count(b)==A.count(c)==N//3) and (a^b==c)
        1/0
        
if ans:print("Yes")
else:print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
*A, = map(int,input().split())

if N%3:
    ans = True
    for a in A:
        if a:ans=False;break
else:
    B = set(A)
    l = len(B)
    ans = True
    if l>3 or l==2:ans = False
    elif l==1:
        for b in B:
            if b:ans=False;break
        1/0
    else:
        a,b,c = B
        ans = ans and (A.count(a)==A.count(b)==A.count(c)==N//3) and (a^b==c)
        
if ans:print("Yes")
else:print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
*A, = map(int,input().split())

if N%3:
    ans = True
    for a in A:
        if a:ans=False;break
    1/0
else:
    B = set(A)
    l = len(B)
    ans = True
    if l>3 or l==2:ans = False
    elif l==1:
        for b in B:
            if b:ans=False;break
    else:
        a,b,c = B
        ans = ans and (A.count(a)==A.count(b)==A.count(c)==N//3) and (a^b==c)
        
if ans:print("Yes")
else:print("No")

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
answer="No"

#文字が全部0
if all(a==0 for a in A):
  answer="Yes"

#0aa0aaという並びに出来る
#0がN/3個,aが2N/3個で数字は二種類
elif len(c)==2 and N%3==0:
  if all(AA[:third]==0):
    answer="Yes"
     
#abc,abc...,abcという並びに出来る
#aがN/3個,bがN/3個,cがN/3個で数字は三種類
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if bin(AA[0]^AA[third])==bin(AA[2*third]) and \
    bin(AA[third]^AA[2*third])==bin(AA[0]) and \
    bin(AA[2*third]^AA[0])==bin(AA[third]):
      answer="Yes"
    
print(answer)

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
answer="No"

#文字が全部0
if all(a==0 for a in A):
  answer="Yes"

#0aa0aaという並びに出来る
#0がN/3個,aが2N/3個で数字は二種類
elif len(c)==2 and N%3==0:
  if all(AA[:third]==0):
    answer="Yes"
     
#abc,abc...,abcという並びに出来る
#aがN/3個,bがN/3個,cがN/3個で数字は三種類
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if bin(AA[0]^AA[third])==bin(AA[2*third]) and \
    (AA[third]^AA[2*third])==bin(AA[0]) and \
    (AA[2*third]^AA[0])==bin(AA[third]):
      answer="Yes"
    
print(answer)

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
answer="No"

#文字が全部0
if all(a==0 for a in A):
  answer="Yes"

#0aa0aaという並びに出来る
#0がN/3個,aが2N/3個で数字は二種類
elif len(c)==2 and N%3==0:
  if all(AA[:third]==0):
    answer="Yes"
     
#abc,abc...,abcという並びに出来る
#aがN/3個,bがN/3個,cがN/3個で数字は三種類
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    answer="Yes"
    
print(answer)

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3

#文字が全部0
if all(a==0 for a in A):
  print("Yes")

#0aa0aaという並びに出来る
#0がN/3個,aが2N/3個で数字は二種類
elif len(c)==2 and N%3==0:
  if all(AA[:third]==0):
    print("Yes")
     
#abc,abc...,abcという並びに出来る
#aがN/3個,bがN/3個,cがN/3個で数字は三種類
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    print("Yes")
    
else:
  print("No")

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ret = 'No'
c = Counter(A)
if all([i == 0 for i in c]):
    ret = 'Yes'
else:
    v = set(list([i[1] for i in c.items()]))
    if len(c) == 3 all([i == N/3 for i in v]):
        ret = 'Yes'
    elif len(c) == 2 and 0 in c:
        for i in c.items():
            if i[0] == 0 and i[1] == N/3:
                ret = 'Yes'

print(ret)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
OK = True


for i in range(0, N):
    if a[i-1] ^ a[i]^ a[i+1%N] != 0:
        OK = False
        break

print("Yes" if OK else "No")

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))

if N % 3 == 0:
    check = False
    for i in range(N):
        a1 = A[i]
        a2 = A[i+1]
        a3 = A[ (i+2+N) % N ]
        if a1^a2^a3 == 0:
            check = True
        else:
            check = False
            break
    if check:
        print("Yes")
        exit()
else:
    check = False
    for i in range(N):
        if A[i] == 0:
            check = True
        else:
            check = False
    if check:
        print("Yes")
        exit()

print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))

if N % 3 == 0:
    check = False
    for i in range(N-1):
        a1 = A[i]
        a2 = A[i+1]
        a3 = A[ (i+2+N) % N ]
        if a1^a2^a3 == 0:
            check = True
        else:
            check = False
            break
    if check:
        print("Yes")
        exit()
else:
    check = False
    for i in range(N):
        if a[i] == 0:
            check = True
        else:
            check = False
    if check:
        print("Yes")
        exit()
        
print("No")

Submission status: Runtime Error

Solution code:
from functools import reduce
from operator import xor

R = lambda: map(int, input().split())
 
n = int(input())
if n % 3:
    ans = 'YNeos'[any(R())::2]
else:
    a = sorted(R())
    m = n // 3
    if reduce(a[::m], xor):
        ans = 'No'
    elif any(len(set(a[i:i + m])) > 1 for i in range(0, n, m)):
        ans = 'No'
    else:
        ans = 'Yes'
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
from sys import stdin

def main():
    N = int(input())
    A = map(int, input().split())

    cnt = Counter(A).most_common()
    n = N // 3
    l = len(cnt)
    if cnt[0][0] == 0 and l == 1:
        print('Yes')
        return
    if cnt[1][0] == 0 and cnt[1][1] == n and l == 2:
        print('Yes')
        return
    if N % 3:
        print('No')
        return

    if cnt[0][0] ^ cnt[1][0] == cnt[2][0] and cnt[0][1] == cnt[1][1] == n:
        print('Yes')
    else:
        print('No')

input = lambda: stdin.readline()
main()

Submission status: Runtime Error

Solution code:
from math import log2, floor
from operator import or_
from functools import reduce

n = int(input())
a = list(map(int, input().split()))

if max(a) == 0 :
    bl = [0]
else :
    bl = [0 for _ in range(floor(log2(max(a)))+1)]
for ai in a :
    aj = ai
    if ai == 0 :
        pass
    else :
        for i in range(floor(log2(ai))+1) :
            if aj & 1 == 1 :
                bl[i] += 1
            aj >>= 1

ans = reduce(or_, map(lambda x : x&1, bl))
if ans :
    print("No")
else :
    print("Yes")

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
if all(map(lambda x:x==0,A)) or (sum(map(lambda x:x==0,A))==(N/3) and (len(set(A))==2) or (len(set(A))==3) and list(set(A))[0]^list(set(A))[1]^list(set(A))[2]==0 and A.count(list(set(A))[0])==A.count(list(set(A))[1]) and A.count(list(set(A))[1])==A.count(list(set(A))[2]) and A.count(list(set(A))[3])==A.count(list(set(A))[0])):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
a_list = list(map(int,input().split()))

l = len(set(a_list))

def check():
    counter = Counter(a_list)
    if l == 1:
        if a_list[0] == 0:
            return True
        return False
    if l == 2:
        if Counter[0] == 3/N:
            return True
        return False
    if l == 3:
        x,y,z = set(a_list)
        if int(bin(x^y^z), 0) == 0 and set(list(counter.values()))==set([3/N]):
            return True
        return False
    return False

if check():
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
import math

sys.setrecursionlimit(10**6)



def put_que(n):
    global tmp, tree
    if n in tmp:
        return
    que.append(n)
    tmp.add(n)
    for i in tree[n]:
        put_que(i)


def set_answer(n, i):
    global tree, answer
    # print(n, '-',i, tree[n])
    answer.append('{} {}'.format(n, i))
    tree[i].remove(n)

def search(n):
    global tree, que, answer

    if len(tree[n]) & 1:
        i = tree[n].pop()
        answer.append('{} {}'.format(i, n))
        tree[i].remove(n)

        j = tree[i].pop()
        answer.append('{} {}'.format(i, j))
        tree[j].remove(i)
    
    while len(tree[n]) > 0:
        i = tree[n].pop()
        answer.append('{} {}'.format(n, i))
        tree[i].remove(n)

def main():
    global tree, que, answer

    N, m = list(map(int, input().split()))
    tree = {i+1 : set() for i in range(N)}

    for _ in range(m):
        i, j = list(map(int, input().split()))
        tree[i].add(j)
        tree[j].add(i)

    if m % 2 == 1:
        print(-1)
        return

    # print(tree)
    put_que(1)
    for n in reversed(que):
        search(n)
            
    print(*answer, sep="\n")


if __name__ == "__main__":
    tmp = set()
    que = []
    answer = []
    main()

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
a=1;for i in A:a^=i 
print(["No","Yes"][a==1])

Submission status: Runtime Error

Solution code:
class Bridge:
    def __init__(self, nodeA, nodeB):
        self.edges = [BridgeEdge(nodeA, self), BridgeEdge(nodeB, self)]
        nodeA.addEdge(self.edges[1])
        nodeB.addEdge(self.edges[0])
        self.dir = True
        self.vec = None

class BridgeEdge:
    def __init__(self, node, edge):
        self.edge = edge
        self.node = node
    def another(self):
        return self.edge.edges[1 if self.edge.edges[0] == self else 0]

class Node:
    def __init__(self, id):
        self.id = id
        self.bridges = []
        self.parent = None
        self.judge = 0
    def addEdge(self, bridgeEdge):
        self.bridges.append(bridgeEdge)
    def __repr__(self):
        return str((self.id, None if self.parent is None else self.parent.node.id))

N, M = map(int, input().split())

nodes = [Node(i) for i in range(N+1)]
bridges = []
for A, B in (map(int, input().split()) for _ in range(N)):
    bridges.append(Bridge(nodes[A], nodes[B]))

s = [(None, nodes[1])]
idx = 0
ok = True
while idx < len(s):
    pre, cur = s[idx]
    idx += 1


    for nxt in cur.bridges:
        if nxt.node.judge <= 0:
            nxt.node.parent = nxt.another()
            cur.judge += 1
            nxt.edge.vec = (cur.id, nxt.node.id)
            s.append((cur, nxt.node))


    if cur.judge % 2 == 1:
        ok = not ok
        wrk = cur
        while wrk.parent is not None:
            br = wrk.parent.edge
            br.dir = not br.dir
            wrk = wrk.parent.node

if ok:
    for br in bridges:
        if br.dir:
            print("{} {}".format(br.vec[1], br.vec[0]))
        else:
            print("{} {}".format(br.vec[0], br.vec[1]))
else:
    print("-1")

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))

s = set(A)

if len(s) == 1 and s[0] == 0:
  print("Yes")
  exit(0)

for i in range(N):
    post_index = i + 1 if i + 1 <= (N - 1) else 0
    pre = A[i - 1]
    post = A[post_index]
    if (pre ^ post) != A[i]:
        print("No")
        exit(0)
 
print("Yes")

Submission status: Runtime Error

Solution code:
def main():
    global tree, que, answer

    N, m = list(map(int, input().split()))
    tree = {i+1 : set() for i in range(N)}

    for _ in range(m):
        i, j = list(map(int, input().split()))
        tree[i].add(j)
        tree[j].add(i)

    if m % 2 == 1:
        print('-1')
        return

    print(*answer, sep="\n")


if __name__ == "__main__":
    tmp = set()
    que = []
    answer = []
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
l = len(set(a))
if l > 3:
	print("No")
elif l == 1:
	if a[0] == 0:
		print("Yes")
	else:
		print("No")
elif n%3 != 0:
	print("No")
elif l == 2:
	if 0 not in set(a):
		print("No")
	elif a.count(0) == n//3:
		print("Yes")
	else:
		print("No")
else:
	for x in list(set(a)):
		if a.count(x) != n//3:
			print("No")
			break
	elif list(set(a))[0] ^ list(set(a))[1] == list(set(a))[2]:
		print("Yes")
	else:
		print("No")

Submission status: Runtime Error

Solution code:
import collections

N = input()
N = int(N)
a = [ int(i) for i in input().split()]
c = collections.Counter(a)
hoge = True

def check(i,j):
    c[j] -= 1
    for k in range(len(a)-1):
        if c[i^j] <= 0:
            return False
        c[i^j]-=1
        i2 = j
        j = i^j
        i = i2
    return True


if !check(a[0],a[1]):
    hoge = False

if hoge:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
size = int(input())
nums = list(map(int, input().split()))

# size = 3
# nums = [1, 2, 3]

numu = list(set(nums))
if len(numu) == 1 and numu[0] == 0:
  print("Yes")
  quit()

if len(numu) == 2 and nums.count(0) == 1 \
    and nums.count(0) * 3 == size:
  print("Yes")
  quit()

if not nums.count(numu[0]) == nums.count(numu[1]) == nums.count(numu[2]):
  print("No")
  quit()

if len(numu) == 3:
  if numu[0] ^ numu[2] == numu[1] \
      and numu[1] ^ numu[0] == numu[2] \
      and numu[2] ^ numu[1] == numu[0]:
    print("Yes")
    quit()

print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
d = list(map(int,input().split()))
d_unique = list(set(d))

if len(d_unique) == 1:
    if d_unique[0] == 0:
        print('Yes')
    else:
        print('No')

else:
    if N%3 != 0 :
        print('No')

    else :
        if len(d_unique) == 2 :
            i1 = d_unique[0]
            i2 = d_unique[1]
            len_i1 = d.count(i1)
            len_i2 = d.count(i2)
            if len_i1 ==  N/3 and i1 & i2 & i2 = 0:
                print('Yes')
            elif len_i2 ==  N/3 and i1 & i1 & i2 != 0:
                print('Yes')                
            else :
                print('No')

        elif len(d_unique) == 3 :
            i1 = d_unique[0]
            i2 = d_unique[1]
            i3 = d_unique[2]
            len_i1 = d.count(i1)
            len_i2 = d.count(i2)
            len_i3 = d.count(i3)
            if i1 & i2 & i3 != 0:
                print('No')     
            else:
                if len_i1 ==  N/3 and len_i2 == N/3 :
                    print('Yes')
                else :
                    print('No')

Submission status: Runtime Error

Solution code:
N = int(input())
d = list(map(int,input().split()))
d_unique = list(set(d))

if len(d_unique) == 1:
    if d_unique[0] == 0:
        print('Yes')
    else:
        print('No')

else:
    if N%3 != 0 :
        print('No')

    else :
        if len(d_unique) == 2 :
            i1 = d_unique[0]
            i2 = d_unique[1]
            len_i1 = d.count(i1)
            len_i2 = d.count(i2)
            if len_i1 ==  N/3 and i1 & i2 & i2 = 0: :
                print('Yes')
            elif len_i2 ==  N/3 and i1 & i1 & i2 != 0: :
                print('Yes')                
            else :
                print('No')

        elif len(d_unique) == 3 :
            i1 = d_unique[0]
            i2 = d_unique[1]
            i3 = d_unique[2]
            len_i1 = d.count(i1)
            len_i2 = d.count(i2)
            len_i3 = d.count(i3)
            if i1 & i2 & i3 != 0:
                print('No')     
            else:
                if len_i1 ==  N/3 and len_i2 == N/3 :
                    print('Yes')
                else :
                    print('No')

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    a = LI()
    a.sort()
    x = list(set(a))
    if len(x) > 3:
        print("No")
        return
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    elif len(x) == 3:
        x1 = d[x[0]]
        x2 = d[x[1]]
        x3 = d[x[2]]
        if ((x[0] ^ x[1] ^ x[2]) == 0) and (x1 == x2 == x3):
            print("Yes")
        else:
            print("No")
    elif len(x) == 2:
        x1 = d[0]
        x2 = d[x[1]]
        if x1 * 2 == x2:
            print("Yes")
        else:
            print("No")
    elif len(x) == 1:
        if x[0] == 0:
            print("Yes")
        else:
            print("No")
    return

#B
def B():
    n, m = LI()
    if m % 2:
        print(-1)
        return
    edg = [[] for _ in range(n)]
    ins = defaultdict(int)
    c = defaultdict(int)
    for _ in range(m):
        a, b = LI_()
        edg[a].append(b)
        edg[b].append(a)
        ins[a] += 1
        ins[b] += 1
    dag = [[] for _ in range(n)]
    q = deque()
    q.append((0, -1))
    for i in edg[0]:
        q.append((i, 0))
    while q:
        now, per = q.pop()
        if per == -1:
            continue
        if c[now]:
            pass
        
    for d in dag:
        if len(d) % 2:
            print(-1)
            return
    for num, d in enumerate(dag):
        for x in d:
            print(num + 1, x + 1)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Runtime Error

Solution code:
n=int(input())
l = list(map(int,input().split()))
s = set(l)
sl = sorted(list(s))
if len(s)==1 and sl[0]==0:
  print("Yes")
elif n%3==0 and l.count(sl[1])==(2*n)//3 and l.count(sl[0])==n//3 and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==3 and l.count(sl[0])==l.count(sl[1])==l.count(sl[2]):
  if sl[0]^sl[1]^sl[2]==0:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Runtime Error

Solution code:
n=int(input())
l = list(map(int,input().split()))
s = set(l)
sl = sorted(list(s))
if len(s)==1 and sl[0]==0:
  print("Yes")
elif n%3==0 and l.count(sl[1])==2*n//3 and l.count(sl[0])==n//3 and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==3 and l.count(sl[0])==l.count(sl[1])==l.count(sl[2]):
  if sl[0]^sl[1]^sl[2]==0:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
if n % 3 != 0:
    print("No")
    quit()
d = {}
for i in l:
    if i in d.keys():
        d[i] += 1
    else:
        if len(d) == 3:
            print("No")
            quit()
        d[i] = 1
if len(d) > 3:
    print("No")
    quit()
a = l[0]
b = l[1]
e = {}
b = l[i]
c = a ^ b
e[a] = int(n / 3)
e[b] = int(n / 3 * (2 if b in e else 1))
e[c] = int(n / 3 if c not in e else e[c] + n / 3)
if (
        d[a] == e[a] and
        d[b] == e[b] and
        d[c] == e[c]
        ):
    print("Yes")
    quit()
print("No")

Submission status: Runtime Error

Solution code:
from collections import defaultdict

n = int(input())
a = tuple(map(int, input().split()))

can = True
if n % 3 == 0:
    d = defaultdict(int)
    for aa in a:
        d[aa] += 1
    m = n // 3

    t = []
    for number, cnt in d.items():
        if cnt % m != 0:
            can = False
            break
        else:
            for _ in range(cnt // m):
                t.append(number)
    # print(t)
    if any(t[(0 + i) % 3] ^ t[(1 + i) % 3] != t[(2 + i) % 3] for i in range(3)):
        can = False

else:
    if any(aa != 0 for aa in a):
        can = False

print('Yes' if can else 'No')

Submission status: Runtime Error

Solution code:
import sys

n = int(input())
a = list(map(int, input().split()))

is_3n = True
if n % 3 != 0:
    is_3n = False

is_fulfill = False
if is_3n:
    is_zero = list(filter(lambda x: x == 0, a))
    if len(is_zero) == 0:
        is_fulfill = True

    if not is_fulfill:
        is_zero = list(filter(lambda x: x == 0), a)
        if len(is_zero) == n / 3:
            a_not_zero = list(filter(lambda x: x != 0, a))
            a_x = list(filter(lambda x: x == a_not_zero[0], a_not_zero))
            if len(a_x) == 2 * n / 3:
                is_fulfill = True

    if not is_fulfill:
        x = a[0]
        is_y = False
        for i in a:
            if i != x:
                y = i
                is_y = True
                break
        """        
        if not is_y:
            print("No")
            sys.exit()
        """
        is_z = False
        for i in a:
            if i != x and i != y:
                z = i
                is_z = True
                break
        """
        if not is_z:
            print("No")
            sys.exit()
        """
        if is_y and is_z and x ^ y ^ z == 0:
            a_x = list(filter(lambda l: l == x, a))
            if len(a_x) == n / 3:
                a_y = list(filter(lambda x: x == y, a))
                if len(a_y) == n / 3:
                    is_fulfill = True

if is_fulfill:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys

n = int(input())
a = list(map(int, input().split()))
"""
if n % 3 != 0:
    print("No")
    sys.exit()
"""
is_fulfill = False

is_zero = list(filter(lambda x: x == 0, a))
if len(is_zero) == 0:
    is_fulfill = True

if not is_fulfill:
    is_zero = list(filter(lambda x: x == 0), a)
    if len(is_zero) == n / 3:
        a_not_zero = list(filter(lambda x: x != 0, a))
        a_x = list(filter(lambda x: x == a_not_zero[0], a_not_zero))
        if len(a_x) == 2 * n / 3:
            is_fulfill = True

if not is_fulfill:
    x = a[0]
    is_y = False
    for i in a:
        if i != x:
            y = i
            is_y = True
            break
    if not is_y:
        print("No")
        sys.exit()
    is_z = False
    for i in a:
        if i != x and i != y:
            z = i
            is_z = True
            break
    if not is_z:
        print("No")
        sys.exit()

    if x ^ y ^ z == 0:
        a_x = list(filter(lambda l: l == x, a))
        if len(a_x) == n / 3:
            a_y = list(filter(lambda x: x == y, a))
            if len(a_y) == n / 3:
                is_fulfill = True

if is_fulfill:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys

n = int(input())
a = list(map(int, input().split()))

if n % 3 != 0:
    print("No")
    sys.exit()

is_fulfill = False

is_zero = list(filter(lambda x: x == 0, a))
if len(is_zero) == 0:
    is_fulfill = True

if not is_fulfill:
    is_zero = list(filter(lambda x: x == 0), a)
    if len(is_zero) == n / 3:
        a_not_zero = list(filter(lambda x: x != 0, a))
        a_x = list(filter(lambda x: x == a_not_zero[0], a_not_zero))
        if len(a_x) == 2 * n / 3:
            is_fulfill = True

if not is_fulfill:
    x = a[0]
    is_y = False
    for i in a:
        if i != x:
            y = i
            is_y = True
            break
    if not is_y:
        print("No")
        sys.exit()
    is_z = False
    for i in a:
        if i != x and i != y:
            z = i
            is_z = True
            break
    if not is_z:
        print("No")
        sys.exit()

    if x ^ y ^ z == 0:
        a_x = list(filter(lambda l: l == x, a))
        if len(a_x) == n / 3:
            a_y = list(filter(lambda x: x == y, a))
            if len(a_y) == n / 3:
                is_fulfill = True

if is_fulfill:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
# print(N, A)

ans = list(set(A))
if len(ans) > 3:
    print('No')
    exit()

a0 = ans[0]
a1 = ans[1]
a2 = ans[2]

if a0 ^ a1 == a2:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))

if n % 3 != 0:
    print("No")
    sys.exit()

is_fulfill = False

is_zero = list(filter(lambda x: x == 0, a))
if len(is_zero) == 0:
    is_fulfill = True

if not is_fulfill:
    is_zero = list(filter(lambda x: x == 0), a)
    if len(is_zero) == n / 3:
        a_not_zero = list(filter(lambda x: x != 0, a))
        a_x = list(filter(lambda x: x == a_not_zero[0], a_not_zero))
        if len(a_x) == 2 * n / 3:
            is_fulfill = True

if not is_fulfill:
    x = a[0]
    is_y = False
    for i in a:
        if i != x:
            y = i
            is_y = True
            break
    if not is_y:
        print("No")
        sys.exit()
    is_z = False
    for i in a:
        if i != x and i != y:
            z = i
            is_z = True
            break
    if not is_z:
        print("No")
        sys.exit()

    if x ^ y ^ z == 0:
        a_x = list(filter(lambda l: l == x, a))
        if len(a_x) == n / 3:
            a_y = list(filter(lambda x: x == y, a))
            if len(a_y) == n / 3:
                is_fulfill = True

if is_fulfill:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
from collections import deque, defaultdict
from copy import copy

def main():
    N = int(input())
    _ = input().split()
    D_ = defaultdict(int)
    a_line = []
    for i, a in enumerate(_):
        a_ = int(a)
        D_[a_] += 1
        if i == 0:
            start = a_
            D_[start] -= 1
        a_line += [a_]

    if len(D) >= 4:
        print('No')
        return

    Q = []
    for a in a_line:
        D = copy(D_)
        D[a] -= 1
        Q += [(start, a, D, N-2)]
    Q = deque(Q)

    while len(Q):
        a, b, D, count = Q.popleft()
        c = a ^ b
        d_ = D.get(c, None)
        if d_ is None or d_ == 0:
            continue
        D[d_] -= 1
        count -= 1
        if count == 0:
            print('Yes')
            return
        Q.append((b, c, D, count))

    print('No')
    return

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
std_n = int(input())
std_list = tuple(map(int, input().split()))
std_set = set(std_list)

if std_set == {0}:
    print("Yes")
    exit()
elif len(std_set) == 2:
    if 0 in std_set:
        if std_list.count(0) * 3 == std_n:
            print("Yes")
            exit()
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()
elif len(std_set) == 3:
    a, b, c = tuple(std_set)
    if (std_list.count(a) == std_list.count(b)) and (std_list.count(b) == std_list.count(c)):
        if int(str(int(format(a, "b")) ^ int(format(b, "b"))), 2) == c:
            print("Yes")
            exit()
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()
else:
    print("No")
    exit()