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 .

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
flag = False
dic = collections.Counter(a)
if len(dic) == 1:
    if 0 in dic:
        print('Yes')
    else:
        print('No')
elif len(dic) == 2:
    if 0 in dic:
        if dic[0] == n/3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(dic) == 3:
    pre = 0
    for k,v in dic.items():
        if v != n/3:
            print('No')
            sys.exit()
        pre = pre^k
    if pre == 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Solution (Python):
from collections import Counter

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

if A.count(0) == N:
    print("Yes")
    exit()

d = Counter(A)
if len(d.keys()) > 3:
    print("No")
    exit()
elif len(d.keys()) == 3:
    a, b, c = d.keys()
    if d[a] == d[b] == d[c] and a ^ b ^ c == 0:
        print("Yes")
    else:
        print("No")
    exit()
elif len(d.keys()) == 2:
    a, b = d.keys()
    if a * b != 0:
        print("No")
    else:
        if a != 0:
            d[a], d[b] = d[b], d[a]  
        if d[a] * 3 == N and 3 * d[b] == 2 * N:
            print("Yes")
        else:
            print("No")
    exit()
print("No")

Solution (Python):
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    As = [int(item) for item in input().split()]
    As.sort()
    temp_set = set(As)
    is_true = True
    
    if len(temp_set) == 1:
        if As[0] != 0:
            is_true = False
    elif len(temp_set) == 2:
        x_num = As.count(max(As))
        zero_num = As.count(0)
        if x_num != 2*zero_num:
            is_true = False

    elif len(temp_set) == 3:
        temp_cnt = collections.Counter(As)
        
        temp_set = list(set(As))
        if temp_cnt[temp_set[0]] == temp_cnt[temp_set[1]] == temp_cnt[temp_set[2]]:
            temp_keys = list(temp_cnt.keys())
            if temp_keys[0] ^ temp_keys[1] ^ temp_keys[2] == 0:
                is_true = True
            else:
                is_true = False
        else:
            is_true = False
        
    else:
        is_true = False

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



if __name__ == "__main__":
    resolve()

Solution (Python):
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
m = c.most_common()

if (len(m)==1) and (m[0][0]==0):
  print('Yes')
elif (m[0][1]==2*N//3) and (m[1][0]==0) and (len(m)==2):
  print('Yes')
elif (m[0][1]==N//3) and (m[1][1]==N//3) and (m[2][1]==N//3) and (m[0][0]^m[1][0]^m[2][0]==0):
  print('Yes')
else:
  print('No')

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

C = Counter(A)

if C[0] == N:
  print('Yes')
elif N%3 > 0:
  print('No')
elif len(C) == 2 and C[0] == N//3:
  print('Yes')
elif len(C) == 3:
  k = list(C.keys())
  v = list(C.values())
  if v[0] == v[1] and v[1] == v[2]:
    if k[0] ^ k[1] ^ k[2] == 0:
      print('Yes')
      exit(0)
      
  print('No')
else:
  print('No')

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil





def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    d = defaultdict(int)
    for e in a:
        d[e] += 1
    ks = list(d.keys())
    m = len(ks)
    if m < 4:
        x = n / 3
        if m == 1 and ks[0] == 0:
            print("Yes")
            return
        elif m == 2:
            if d[0] == x:
                print("Yes")
                return
        elif m == 3:
            a, b, c = ks
            if d[a] == d[b] and d[a] == d[c] and (a^b^c) == 0:
                print("Yes")
                return
    
    print("No")


    


    
    
    
t = 1

for case in range(1,t+1):
    ans = solve()


"""

R s
S p
P r

"""

Solution (Python):
from collections import Counter

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

cnt = 0
for i in a:
    cnt ^= i

if n % 3 == 0 and all(a[i] % (n // 3) == 0 for i in a):
    print('Yes' if (cnt == 0 or a[0] == n // 3) else 'No')
else:
    print('Yes' if a[0] == n else 'No')

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
if A.count(0)==N:
    print("Yes")
elif N%3!=0:
    print("No")
elif len(set(A))==2:
    if 0 in set(A):
        if A.count(0)==N/3:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(set(A))==3:
    xor=0
    for a in set(A):
        if A.count(a)==N/3:
            xor^=a
        else:
            print("No")
            exit()
    if xor==0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Solution (Python):

from collections import Counter

n = int(input())
nums = [int(i) for i in input().split()]
c = Counter(nums)

if sum(nums) == 0:
    print('Yes')
elif len(c) == 2:
    for k, v in c.items():
        if k == 0:
            if v != n // 3:
                print('No')
                break
        else:
            if v != n // 3 * 2:
                print('No')
                break
    else:
        print('Yes')
elif len(c) == 3:
    t = 0
    for k, v in c.items():
        if v != n // 3:
            print('No')
            break
        t ^= k
    else:
        if t:
            print('No')
        else:
            print('Yes')
else:
    print('No')

Solution (Python):
import sys,collections
input = sys.stdin.readline

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

if sum(a) == 0:
    print('Yes')
    exit()

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

ac = collections.Counter(a)

if len(ac) == 2 and ac[0] ==N/3:
    print('Yes')
    exit()


if len(ac) != 3 :
    print('No')
    exit()
else:
    lk1,lk2,lk3 = ac.keys()
    lv1,lv2,lv3 = ac.values()
if lv1 == lv2 ==lv3:
    if lk1^lk2 == lk3:
        print('Yes')
    else:
        print('No')
else:
    print('No')
    exit()

Solution (Python):
n = int(input())
la = [int(w) for w in input().split()]

x = la[0]

for a in la[1:]:
    x ^= a

cond = x == 0
print("Yes" if cond else "No")

Solution (Python):
N = input()
a = list(map(int,input().split()))
el = sorted(list(set(a)))

if len(el) == 1:
  if el[0] == 0:
    print("Yes")
  else:
    print("No")
elif len(el) == 2 :
  if a.count(0)*2 == a.count(el[1]):
    print("Yes")
  else:
    print("No")
elif len(el) == 3 and el[0]^el[1]^el[2] == 0 and a.count(el[1]) == a.count(el[2]) and a.count(el[1]) == a.count(el[0]):
      print("Yes")
else:
  print("No")

Solution (Python):
n = int(input())
A  = list(map(int, input().split()))
if sum(A)==0:
    print('Yes')
    exit()
if n%3==0:
    a=A[0]
    for i in range(1,n):
        a = a^A[i]
    if a==0:
        print('Yes')
        exit()
print('No')

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(N):
    ans ^= a[i]

if(ans == 0):
    print("Yes")
else:
    print("No")

Solution (Python):
N=int(input())
a=input().split()
A=[int(b) for b in a]

number=A[0]

for n in range(1,N):
    number=number^A[n]

if number==0:
    print('Yes')
else:
    print('No')

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

ans = 0
for i in range(n):
    ans ^= a[i]

if ans == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
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()))
v = 0
for num in a:
    v ^= num
if v==0:
    ans = "Yes"
else:
    ans = "No"
print(ans)

Solution (Python):
from collections import Counter

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

c = Counter(A)

t = 0
for a in A:
    t ^= a

if c[0] == N:
    print('Yes')
elif N % 3 == 0:
    if c[0] == int(N//3) and len(c) == 2:
        print('Yes')
    elif len(c) == 3 and t == 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = i()
a = l()

for i in range(N):
    ans^=a[i]

print("Yes" if ans == 0 else "No")

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
XOR=0
for i in range(N):
    XOR^=a[i]
print("Yes" if XOR==0 else "No")

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
XOR=0
for i in range(len(a)):
    XOR^=a[i]
print("Yes" if XOR==0 else "No")

Solution (Python):
N=int(input())
a=list(map(int,input().split()))

d={}
for h in range(1,N):
    if a[h] in d:
        d[a[h]]+=1
    else:
        d[a[h]]=1
ans="Yes"
b=[a[0]]

for h in range(1,N):
    t=a[h]^a[0]
    if t in d:
        b.append(a[h])
        d[a[h]]-=1
        if d[a[h]]==0:
            del d[a[h]]
        break
    if h==N-1:
        ans="No"

if ans=="Yes":
    for i in range(1,N+1):
        if i==h:
            continue
        if i==N:
            t=b[-1]^b[-2]
            if t!=b[0]:
                ans="No"
            break
        t=b[-1]^b[-2]
        if t in d:
            b.append(t)
            d[t]-=1
            if d[t]==0:
                del d[t]
        else:
            ans="No"
            break

print(ans)

Solution (Python):
import functools

if __name__ == "__main__":
    N = int(input())
    A = [int(x) for x in input().split(" ")]
    a = functools.reduce(lambda x, y: x ^ y, A, 0)
    if a == 0:
        print("Yes")
    else:
        print("No")

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
flg=False
if all(a[i]==0 for i in range(n)):flg=True
if n%3==0:
    l=Counter(a)
    ans=l.most_common()
    if len(ans)==2:
        flg1,flg2=False,False
        for i,j in ans:
            if i==0 and n%j==0 and n//j==3:
                flg1=True
            if j/n==2/3:
                flg2=True
            if flg1 and flg2:
                flg=True
    if len(ans)==3:
        flg3=True
        tmp=0
        for i in range(3):
            tmp^=ans[i][0]
            if ans[i][1]*3!=n:
                flg3=False
            if flg3 and tmp==0:
                flg=True
if flg:
    print("Yes")
else:
    print("No")

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt_a = Counter(a)

if n % 3 == 0:
    if cnt_a[0] == n:
        print('Yes')
    elif len(set(a)) == 2 and 0 in set(a) and cnt_a[0] == n // 3:
        print('Yes')
    elif len(set(a)) == 3:
        x, y, z = set(a)
        if cnt_a[x] == n // 3 and cnt_a[y] == n // 3 and cnt_a[z] == n // 3 and x ^ y ^ z == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    if cnt_a[0] == n:
        print('Yes')
    else:
        print('No')

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
k = l[0]
for i in l[1:]:
    k ^= i
if k != 0:
    print('No')
else:
    print('Yes')

Solution (Python):
def main():
    n = int(input())
    A=[int(i) for i in input().split()]
    k = A[0]
    for i in A[1:]:
        k^=i
    if(k!=0):
        print("No")
    else:
        print("Yes")




if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
Aall = A[0]
for i in range(1,N):
    Aall ^= A[i]
import sys
flag = True
for i in range(N):
    if A[i]^Aall != A[i]:
        flag = False
        print("No")
        sys.exit()
if flag:
    print("Yes")

Solution (Python):

'''
両隣の数のXORが自身と等しい状態にできる場合Yes、そうでない場合No
例：
N = 3
Ai = 1, 2, 3
1, 2, 3 -> 1, 2, 3 にすることで
2 XOR 3  = 1, 2 XOR 1 = 3, 3 XOR 1 = 1 となるので Yes
XOR の性質は
a XOR a = 0
a XOR 0 = a
a XOR b >= a + b
などがある。
'''
import collections
N = int(input())

L = list(map(int,input().split()))
C = collections.Counter(L)
flg = False
if len(C)>3:
    print('No')
    exit()

if len(C)==3:
    ans = 0
    cnt = []
    for i,v in C.items():
        ans ^= i
        cnt.append(v)
    if ans == 0 and max(cnt) == min(cnt):
        print('Yes')
        exit()
    else:
        print('No')
if len(C) == 2:
    if C[0] == 0:
        print('No')
        exit()
    x = 0
    y = 0
    for i,v in C.items():
        if i == 0 :
            x = v
        else:
            y = v
    if 2 * x == y:
        print('Yes')
        exit()
    else:
        print('No')
        exit()
if len(C) == 1:
    if C[0]>0:
        print('Yes')
        exit()
    else:
        print('No')

Solution (Python):

N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N):
    ans ^= A[i]
if ans == 0:
    print('Yes')
else:
    print('No')

Solution (Python):

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()

a = LIST()
C = Counter(a)
A = sorted(set(a))


if len(A) == 1 and A[0] == 0:
	print("Yes")
elif N%3 == 0:
	if len(A) == 3 and A[0]^A[1] == A[2] and len(set(C.values())) == 1:
		print("Yes")
	elif len(A) == 2 and A[0] == 0 and C[0] == N//3:
		print("Yes")
	else:
		print("No")

else:
	print("No")

Solution (Python):

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()

a = LIST()
C = Counter(a)
A = sorted(set(a))

if N%3 == 0:
	if len(A) == 3 and A[0]^A[1] == A[2] and len(set(C.values())) == 1:
		print("Yes")
	elif len(A) == 2 and A[0] == 0 and C[0] == N//3:
		print("Yes")
	elif len(A) == 1 and A[0] == 0:
		print("Yes")
	else:
		print("No")

elif len(A) == 1 and 0 in a:
	print("Yes")
else:
	print("No")

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

cnt=Counter(a)
if cnt[0]==n:
    print("Yes")
    quit()
if n%3!=0:
    print("No")
    quit()
a.sort()
if cnt[0]==n//3 and cnt[a[-1]]==2*n//3:
    print("Yes")
    quit()


lst=[]
for i in range(n):
    if cnt[a[i]]==n//3:
        if a[i] in lst:
            continue
        else:
            lst.append(a[i])
    else:
        print("No")
        quit()
if lst[0]^lst[1]^lst[2]==0:
    print("Yes")
    quit()
else:
    print("No")

Solution (Python):
n,c,*a=map(int,open(0).read().split())
for i in a:c^=i
print('YNeos'[c>0::2])

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

def rule1(L):
    if len(set(L))!=2:
        return False
    if L.count(0)!=len(L)//3:
        return False
    return True

def rule2(L):
    if len(set(L))!=3:
        return False
    sL = set(L)
    if L.count(list(sL)[0])==L.count(list(sL)[1])==L.count(list(sL)[2]):
        if list(sL)[0] ^ list(sL)[1] ^ list(sL)[2] ==0:
            return True
        else:
            return False
    else:
        return False

if sum(A)==0 or rule1(A) or rule2(A):
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a_dic = dict()
a_set = set()
for num in a:
  if num in a_dic:
    a_dic[num] += 1
  else:
    a_dic[num] = 1
  a_set.add(num)
k = len(a_dic)
a_set = list(a_set)
if k == 1:
  if 0 in a_dic:
    if a_dic[0] == n:
      print('Yes')
      exit()
elif k == 2:
  if a_dic[0] == n/3 and a_dic[a_set[1]] == 2*n/3:
    print('Yes')
    exit()
elif k == 3:
  if a_set[0] ^ a_set[1] ^ a_set[2] == 0:
    if a_dic[a_set[0]] == a_dic[a_set[1]] == a_dic[a_set[2]] == n/3:
      print('Yes')
      exit()
print('No')

Solution (Python):

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))



def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter, xor
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  
from functools import reduce




N = read_a_int()
A = read_ints()
res = reduce(xor, A)
print('Yes' if res == 0 else 'No')

Solution (Python):
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    allxor=0
    for i in range(n):
        allxor = allxor ^ a[i]
    if allxor == 0:
        return 'Yes'
    else:
        return 'No'

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
a.sort()
x = [10**9+1,0]
y = [10**9+1,0]
z = [10**9+1,0]
for i in range(N):
    if x[0] == a[i]:
        x[1] += 1
    else:
        if x[1] == 0:
            x[0] = a[i]
            x[1] += 1
        elif y[0] == a[i]:
            y[1] += 1
        else:
            if y[1] == 0:
                y[0] = a[i]
                y[1] += 1
            elif z[0] == a[i]:
                z[1] += 1
            else:
                if z[1] == 0:
                    z[0] = a[i]
                    z[1] += 1

ans = 'No'
if x[0] == 0:
    if x[1] == N:
        ans = 'Yes'
    elif x[1]*2 == y[1] and x[1] + y[1] == N:
        ans = 'Yes'
if x[1] == y[1] == z[1] and x[1] + y[1] + z[1] == N and x[0]^y[0]^z[0] == 0:
    ans = 'Yes'

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
if set(a) == {0}:
    print('Yes')
    exit()

flag = 0
if n % 3 == 0:
    if len(cnt) == 2:
        if cnt.get(0) == n // 3:flag = 1
    elif len(cnt) == 3:
        if len(set(cnt.values())) == 1:
            new_a = list(cnt.keys())
            if new_a[0]^new_a[1] == new_a[2]:flag = 1

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
if A.count(0)==N:
    print("Yes")
elif N%3!=0:
    print("No")
elif len(set(A))==2:
    if 0 in set(A):
        if A.count(0)==N/3:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(set(A))==3:
    xor=0
    for a in set(A):
        if A.count(a)==N/3:
            xor^=a
        else:
            print("No")
            exit()
    if xor==0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Solution (Python):
from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))
def main():
    
    if c[0] == n:
        ok = True
        return ok
    if n % 3 != 0:
        ok = False
        return ok
    
    if c[0] == n // 3 and len(c) == 2:
        ok = True
        return ok
    
    if len(c) != 3:
        ok = False
        return ok
    xor = 0
    for x in c:
        if c[x] != n // 3:
            ok = False
            return ok
        xor ^= x
    if xor == 0:
        ok = True
    else:
        ok = False
    return ok
        
if __name__ == '__main__':
    print("Yes" if main() else "No")

Solution (Python):



from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    Al = Counter(A)
    x = list(Al)
    x.sort()

    if len(Al)>3:
        print('No')
    elif len(Al)==3:
        cond1 = (x[0]^x[1]^x[2] == 0)
        cond2 = (Al[x[0]] == N//3) and (Al[x[1]] == N//3) and (Al[x[2]] == N//3)
        if cond1 and cond2:
            print('Yes')
        else:
            print('No')

    elif len(Al)==2:
        cond1 = x[0] == 0
        cond2 = (Al[x[0]] == N//3) and (Al[x[1]] == N - N//3)
        if cond1 and cond2:
            print('Yes')
        else:
            print('No')
    elif len(Al)==1:
        cond1 = x[0] == 0
        cond2 = True
        if cond1 and cond2:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()

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

ans='No'
from collections import Counter

c=Counter(a)
keys = list(c.keys())
values =list(c.values())

if keys==[0]:
    ans='Yes'
elif len(keys)==3 and values[0]==n/3 and values[1]==n/3 and keys[0]^keys[1]==keys[2]:
    ans='Yes'
elif len(keys)==2 and c[0]==n/3:
    ans='Yes'

print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
 
t = 0
for a_i in a:
    t ^= a_i
    
print("Yes" if t==0 else "No")

Solution (Python):
from collections import Counter

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

c = Counter(A)


c_set = set(A)


if len(c_set) == 1:
    if c[0] != 0:
        print('Yes')
        exit(0)


elif len(c) == 2:
    if c[0] == N//3:
        print('Yes')
        exit(0)


elif len(c) == 3:
    check = -1
    check_list = []
    for a in c_set:
        check_list.append(a)
        if check == -1:
            check = c[a]
        else:
            if check != c[a]:
                print('No')
                exit(0)

    
    if check_list[0] ^ check_list[1] ^ check_list[2] == 0:
        print('Yes')
        exit(0)
print('No')

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

if len(set(A)) >3 :
  print("No")
elif len(set(A))  == 3 :
  x,y,z = sorted(list(set(A)))[0],sorted(list(set(A)))[1],sorted(list(set(A)))[2]
  if N%3 == 0 and \
  A.count(x) == N//3 and\
  A.count(y) == N//3 and\
  A.count(z) == N//3 and\
  x^y^z == 0:
    print("Yes")
  else:
    print("No")
elif len(set(A)) == 2:
  x,y = sorted(list(set(A)))[0],sorted(list(set(A)))[1]
  if N%3 == 0 and \
  A.count(x) == N//3 and\
  A.count(y) == 2*N//3 and\
  y^y== 0:
    print("Yes")
  else:
    print("No")
else:
  if list(set(A))[0] ==0:
    print("Yes")
  else:
    print("No")

Solution (Python):
import sys
from collections import Counter

N = int(input())
s = Counter(list(map(int, sys.stdin.readline().rsplit())))


if len(s) == 1 and 0 in s:
    print("Yes")

elif len(s) == 2 and s[0] == N // 3:
    print("Yes")

elif len(s) == 3:
    res = 0
    num = set()
    
    for k, v in s.items():
        res ^= k
        num.add(v)
    
    if not res and len(num) == 1:
        print("Yes")
    else:
        print("No")

else:
    print("No")

Solution (Python):
import sys
from collections import Counter

N = int(input())
s = Counter(list(map(int, sys.stdin.readline().rsplit())))

if s[0] == N:
    print("Yes")
elif len(s) == 2 and s[0] == N // 3:
    print("Yes")
elif len(s) == 3:
    res = 0
    num = set()
    for k, v in s.items():
        res ^= k
        num.add(v)
    if not res and len(num) == 1:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
 
if N%3 != 0 and max(As) > 0:
  print('No')
  exit()
  
else:
  n = N//3
  ma = max(As)
  l = len(str(bin(ma))) - 2
  for i in range(l):
    c = 0
    for a in As:
      if (a>>i)%2 == 0:
        c += 1
    if c != n and c != N:
      print('No')
      exit()

print('Yes')

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

if sum(A) == 0:
    print('Yes')
    exit()

if len(A) % 3 != 0:
    print('No')
    exit()

c = Counter(A)
if len(c.values()) == 2:
    values = list(c.values())
    if min(values) == N // 3:
        keys = list(c.keys())
        if 0 in keys:
            print('Yes')
            exit()

if len(c.values()) != 3:
    print('No')
    exit()

keys = list(c.keys())
for i, j, k in ([0, 1, 2], [1, 2, 0], [2, 1, 0]):
    if keys[i] ^ keys[j] != keys[k]:
        print('No')
        exit()

values = list(c.values())
if values[0] != values[1] or values[1] != values[2]:
    print('No')
    exit()

print('Yes')

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

t = 0
for a_i in a:
    t ^= a_i
    
print("Yes" if t==0 else "No")

Solution (Python):
import sys
n=int(input())
a=sorted(list(map(int,input().split())))

p=set(a[:n//3])
q=set(a[n//3:(n//3)*2])
r=set(a[(n//3)*2:n])

flag=True
if n%3!=0:
    flag=False
if len(set(a))==1 and a[0]==0:
    print("Yes")
    sys.exit()
    
if flag and len(p)==1 and len(q)==1 and len(r)==1:
    if a[0] ^ a[n//3]==a[(2*n)//3]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

t=0
for a_i in a:
    t^=a_i
print('Yes' if t==0 else 'No')