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):
N = int(input())
a = list(map(int,input().split()))
b = {}
flag = 0
ke = []
for i in range(N):
    if a[i] in b:
        b[a[i]] += 1
    else:
        b[a[i]] = 1

if 0 in b:
    if b[0] == N:
        flag = 1

if len(b) == 2:    
    for key in b:
        ke.append(key)  
    if 0 in b:
        if b[ke[1]] / b[0] == 2 or b[ke[0]] / b[0] == 2:
            flag = 1

if len(b) == 3:
    for key in b.keys():
        ke.append(key)

    if b[ke[0]] == b[ke[1]] and b[ke[1]] == b[ke[2]]:
        if ke[0] ^ ke[1] == ke[2] or ke[1] ^ ke[2] == ke[0] or ke[0] ^ ke[2] == ke[1]:
            flag = 1

if flag == 1:
    print('Yes')
else:
    print('No')

Solution (Python):

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
k = list(cnt.keys())
k.sort()
if len(k) == 1:
    if k[0] == 0:
        print("Yes")
    else:
        print("No")
    exit()
elif len(k) == 2:
    if cnt[k[0]] == N // 3 and N % 3 == 0:
        print("Yes")
    else:
        print("No")
    exit()
elif len(k) == 3:
    if cnt[k[0]] == cnt[k[1]] == cnt[k[2]] and k[0] ^ k[1] == k[2]:
        print("Yes")
    else:
        print("No")
    exit()
else:
    print("No")
    exit()

Solution (Python):
import collections as c
import sys

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

A = c.Counter(a)

if list(A.keys()) == [0]:
	print("Yes")
	sys.exit()

if len(A.keys()) == 2:
	if 0 not in A.keys():
		print("No")
		sys.exit()
	else:
		if list(A.values())[0]*2 == list(A.values())[1]:
			print("Yes")
			sys.exit()
		else:
			print("No")
			sys.exit()

if len(A.keys()) != 3:
	print("No")
	sys.exit()

x,y,z = A.keys()
if x^y != z:
	print("No")
	sys.exit()

x,y,z = A.values()
if x == y == z:
	print("Yes")
else:
	print("No")

Solution (Python):
import sys
n=int(input())
a=list(map(int,input().split()))
if(len(set(a))==1 and a[0]==0):
    print("Yes")
elif(n%3!=0):
    print("No")
else:
    seta=list(set(a))
    nums=len(set(a))
    if(nums>3):
        print("No")
    elif(nums==3):
        if(a.count(seta[0])==n//3 and a.count(seta[1])==n//3 and a.count(seta[2]) and (seta[0] ^ seta[1] ^ seta[2] == 0)):
            print("Yes")
        else:
            print("No")
    elif(nums==2):
        seta.sort()
        if(seta[0]==0 and a.count(seta[0])==n//3):
            print("Yes")
        else:
            print("No")
    elif(nums==1):
        if(seta[0]==0):
            print("Yes")
        else:
            print("No")

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    c = collections.Counter(a)
    if len(c) > 3:
        return "No"

    k = list(c.keys())
    def f(t):
        for i in range(n-2):
            u = t[i] ^ t[i+1]
            t.append(u)
        if t[0] ^ t[-2] != t[-1] or t[-1] ^ t[1] != t[0]:
            return False
        d = collections.Counter(t)
        if c != d:
            return False
        return True

    for g in k:
        for h in k:
            if f([g,h]):
                return 'Yes'

    return 'No'


print(main())

Solution (Python):
import collections
import itertools


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

def binbin(a,b,c):
    maxlen=max(len(bin(a)[2:]),len(bin(b)[2:]),len(bin(c)[2:]))
    data2={"x":(maxlen-len(bin(a)[2:]))*"0"+bin(a)[2:],"y":(maxlen-len(bin(b)[2:]))*"0"+bin(b)[2:],"z":(maxlen-len(bin(c)[2:]))*"0"+bin(c)[2:]}

    length=len(data2["x"])
    ite=itertools.permutations("xyz")
    for x,y,z in ite:
        data=[]
        for i in range(length):
            if not (int(data2[x][i]) + int(data2[y][i]))%2 == int(data2[z][i]):
                return(0)
    return(1)


if data[0]==N:
    print("Yes")
elif N%3==0:
    mc=data.most_common()
    if data[0] == N//3 and len(data)==2:
        print("Yes")
    elif len(data)==3 and binbin(mc[0][0],mc[1][0],mc[2][0]) and mc[0][1]==mc[1][1]==mc[2][1]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Solution (Python):
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd 
def lcm(a,b):return (a*b) // math.gcd(a,b) 
def iin(): return int(input()) 
def isn(): return input().split() 
def imn(): return map(int, input().split()) 
def iln(): return list(map(int, input().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def comb(l, n): return itertools.combinations(l, n) 
def 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)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

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

if N % 3 != 0:
    print('No')
else:
    d = {}
    for i in range(N):
        if a[i] not in d.keys():
            d[a[i]] = 1
        else:
            d[a[i]] += 1
    if len(d) == 3:
        keys = list(d.keys())
        values = list(d.values())
        if values[0] == values[1] == values[2] and keys[0] ^ keys[1] == keys[2]:
            print('Yes')
        else:
            print('No')
    elif len(d) == 2:
        if 0 in d.keys() and d[0] == N//3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

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

if n%3==0:
    for j in range(3):
        for i in range(j*(n//3),(j+1)*(n//3)-1):
            if a[i]!=a[i+1]:
                print("No")
                exit()
    if a[0]^a[n//3]==a[2*n//3]:
        print("Yes")
    else:
        print("No")
    exit()
for i in range(0,n-1):
    if a[i]!=a[i+1]:
        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')
else:
    if len(a)%3 != 0:
        print('No')
    else:
        counter = Counter(a)
        keys = list(counter.keys())
        vlen = len(set(counter.values()))
        if len(keys) >= 4 or len(keys) == 1:
            print('No')
        else:
            if len(keys) == 2:
                if 0 in counter:
                    if counter[0] == N//3:
                        print('Yes')
                    else:
                        print('No')
                else:
                    print('No')
            else:
                if (vlen == 1) and (keys[0]^keys[1]==keys[2]):
                    print('Yes')
                else:
                    print('No')

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
x = list(set(a))
x.sort()
if len(x) >= 4:
  print("No")
  exit()
if len(x) == 3:
  if x[0]^x[1] == x[2] and 3*a.count(x[0]) == 3*a.count(x[1]) == 3*a.count(x[2]) == n:
    print("Yes")
  else:
    print("No")
  exit()
if len(x) == 2:
  if x[0] == 0 and (2*a.count(x[0]) == 2*a.count(x[1]) == n or 6*a.count(x[0]) == 3*a.count(x[1]) == 2*n):
    print("Yes")
  else:
    print("No")
  exit()
if len(x) == 1:
  if x[0] == 0:
    print("Yes")
  else:
    print("No")

Solution (Python):

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

d = {}
for i in range(N):
    a = A[i]
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1
flag = True
if len(d.keys()) == 1:
    if list(d.keys())[0] == 0:
        flag = True
    else:
        flag = False
elif len(d.keys()) == 2:
    keys = list(sorted(list(d.keys())))
    if d[keys[0]] == N // 3:
        flag = True
    else:
        flag = False
elif len(d.keys()) == 3:
    keys = list(d.keys())
    if keys[0] ^ keys[1] ^ keys[2] == 0:
        if d[keys[0]] == d[keys[1]] == d[keys[2]]:
            flag = True
        else:
            flag = False
    else:
        flag = False
else:
    flag = False
print("Yes" if flag else "No")

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
A.sort()
d = {}
for i in range(N):
    a = A[i]
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1
if len(d.keys()) == 1:
    if list(d.keys())[0] == 0:
        print("Yes")
    else:
        print("No")
elif len(d.keys()) == 2:
    keys = list(sorted(list(d.keys())))
    if d[keys[0]] == N // 3:
        print("Yes")
    else:
        print("No")
elif len(d.keys()) == 3:
    keys = list(d.keys())
    if keys[0] ^ keys[1] ^ keys[2] == 0:
        if d[keys[0]] == d[keys[1]] == d[keys[2]]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

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

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

N = int(input())
a = [int(i) for i in input().split()]

from collections import Counter

Count_a = Counter(a)

if len(Count_a) == 1:
    if Count_a[0] == N:
        print("Yes")
    else:
        print("No")

elif len(Count_a) == 2 and N % 3 == 0:
    if Count_a[0] == N // 3:
        print("Yes")
    else:
        print("No")

elif len(Count_a) == 3 and N % 3 == 0:
    three = list(set(a))
    if three[0] ^ three[1] ^ three[2] == 0:
        for i in range(3):
            if Count_a[three[i]] != N // 3:
                print("No")
                exit()
        print("Yes")
    else:
        print("No")

else:
    print("No")

Solution (Python):
import collections
N = int(input())
a = list(map(int, input().split()))
A = set()
table = collections.defaultdict(int)

for i in range(1, N):
    table[a[i]] += 1

ans = [-1]*N
ans[0] = a[0]
for i in range(1, N):
    if (a[0] ^ a[i]) in table and table[a[0] ^ a[i]] >= 1:
        if a[0] == 0:
            if table[a[i]] == 1:
                continue
        ans[1] = (a[0] ^ a[i])
        ans[2] = a[i]
        table[ans[1]] -= 1
        table[ans[2]] -= 1
        break

if ans[1] == -1:
    print("No")
    exit(0)

for i in range(3, N):
    if (ans[i-1] ^ ans[i-2]) in table and table[ans[i-1] ^ ans[i-2]] >= 1 and table[ans[i-1] ^ ans[i-2]] >= 1:

        ans[i] = ans[i-1] ^ ans[i-2]
        table[ans[i]] -= 1
    else:
        print("No")
        exit(0)
print("Yes")

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・a,b,a+b,a,b,a+b,...
・0,a,a,0,a,a,...
・0,0,0,0,0,0,...
"""

N,*A = map(int,read().split())

def solve(N,A):
    if all(x == 0 for x in A):
        return True
    q,r = divmod(N,3)
    if r:
        return False
    from collections import Counter
    counter = Counter(A)
    n = len(counter)
    if n == 1:
        return False
    if n == 2:
        a,b = counter.keys()
        if a > b:
            a,b = b,a
        if a != 0:
            return False
        
        if counter[0] != N//3:
            return False
        return True
    if n == 3:
        a,b,c = counter.keys()
        for x in [a,b,c]:
            if counter[x] != q:
                return False
        return a^b^c == 0

answer = 'Yes' if solve(N,A) else 'No'
print(answer)

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

Solution (Python):
N = int(input())
a = [int(_) for _ in input().split()]
s = set()
for i in range(N):
    s.add(a[i])
if len(s) == 1 and 0 in s:
    print('Yes')
elif len(s) == 2 and 0 in s:
    if N%3 == 0 and a.count(0) == N//3:
        print('Yes')
    else:
        print('No')
else:
    if N%3 != 0 or len(s) != 3:
        print('No')
    else:
        cnt = []
        for x in s:
            cnt.append(a.count(x))
        if len(set(cnt)) != 1:
            print('No')
        else:
            xor = 0
            for x in s:
                xor ^= x
            if xor == 0:
                print('Yes')
            else:
                print('No')

Solution (Python):
from functools import reduce as f;input();print("YNeos"[f(lambda x,y:x^y,map(int,input().split()))>0::2])

Solution (Python):
from functools import reduce as f;input();print("YNeos"[f(lambda x,y:x^y,map(int,input().split()))!=0::2])

Solution (Python):
from functools import reduce as f;n=int(input());print("YNeos"[f(lambda x,y:x^y,map(int,input().split()))!=0::2])

Solution (Python):
from functools import reduce
n = int(input())
l = list(map(int, input().split()))
if reduce((lambda x, y:x ^ y), l) == 0:
  print("Yes")
else:
  print("No")

Solution (Python):
from functools import reduce
n = int(input())
l = list(map(int, input().split()))
if n%3:
  if max(l) == 0:
    print("Yes")
  else:
    print("No")
else:
  if reduce((lambda x, y:x ^ y), l) == 0:
    print("Yes")
  else:
    print("No")

Solution (Python):
def num2bi(x, k):
  
  out=format(x, '0'+str(k)+'b')
  return out

def f(a, b, c):
  n=len(format(max([a, b, c]), '0b'))
  a=format(a, '0'+str(n)+'b')
  b=format(b, '0'+str(n)+'b')
  c=format(c, '0'+str(n)+'b')
  out=True
  for i in range(n):
    if (a[i]==b[i] and c[i]=='1') or (a[i]!=b[i] and c[i]=='0'):
      out=False
  return out

N=int(input())
a=list(map(int, input().split()))
a.sort()
if sum(a)==0:
  print('Yes')
  exit()
  
if N%3==0 and a[0]==a[N//3-1] and a[N//3]==a[2*N//3-1] and a[2*N//3]==a[-1]:
  if f(a[0], a[N//3], a[2*N//3])==True:
    print('Yes')
    exit()
    
print('No')

Solution (Python):
import sys
from collections import Counter

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

b = list(Counter(a).items())
if sum(a) == 0:
    print("Yes")
    sys.exit()
    
if N % 3 == 0:
    if len(b) != 3:
        if len(b) == 2 and min(b[0][0], b[1][0]) == 0 and min(b[0][1], b[1][1]) == N // 3:
            print("Yes")
            sys.exit()
        print("No")
        sys.exit()
    if b[0][0] ^ b[1][0] ^ b[2][0] != 0 or b[0][1] != N // 3 or b[1][1] != N // 3:
        print("No")
        sys.exit()
    print("Yes")
else:
    print("No")

Solution (Python):
import sys

n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
n_bin = len(bin(max(a_ls))) - 2
a_ls = [bin(a)[2:].zfill(n_bin) for a in a_ls]
cnt = {i : 0 for i in range(n_bin)}
for a in a_ls:
    for i, _a in enumerate(a):
        cnt[i] += _a == "1"
flg = True
if sum(cnt.values()) == 0:
    print("Yes")
elif n % 3 != 0:
    print("No")
else:
    for i in range(n_bin):
        flg &= (cnt[i] == 0 or cnt[i] == n // 3 * 2)
        if not flg:
            break
    if flg:
        print("Yes")
    else:
        print("No")

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
data=[]
lst=[a[0]]
num=1
for i in range(1,n):
    if a[i]==a[i-1]:
        num+=1
    else:
        data.append(num)
        lst.append(a[i])
        num=1
data.append(num)
if len(data)==3 and data[0]==data[1]==data[2]:
    if lst[0]^lst[1]==lst[2]:
        print("Yes")
    else:
        print("No")
else:
    if len(data)==1 and lst[0]==0:
        print("Yes")
    elif len(data)==2 and data[0]*2==data[1]:
        print("Yes")
    else:
        print("No")

Solution (Python):
from collections import Counter as ct
import sys
input = sys.stdin.readline

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

if c[0] == n:
    print("Yes")
elif len(c) == 2 and c[0] * 3 == n:
    print("Yes")
elif len(c) == 3 and len(set(c.values())) == 1:
    a, b, c = c.keys()
    if (a ^ b ^ c) == 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 len([a for a in A if a == 0]) == N:
    print("Yes")
    exit()

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


count = Counter(A)

if len(count.keys()) > 3:
    print("No")
    exit()
elif len(count.keys()) == 3:
    numbers = list(count.keys())
    amounts = list(count.values())
    if numbers[0] ^ numbers[1] ^ numbers[2] == 0 and amounts[0] == N//3 and amounts[1] == N//3 and amounts[2] == N//3:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
elif len(count.keys()) == 2:
    numbers = list(count.keys())
    numbers.sort()
    amounts = list(count.values())
    if numbers[0] == 0 and count[0] == N//3:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
print("No")

Solution (Python):
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    a = collections.Counter(a).most_common()
    if len(a) == 1:
        if a[0][0] == 0:
            print("Yes")
        else:
            print("No")
    elif len(a) == 2:
        if a[1][0] == 0 and a[0][1] == a[1][1] * 2:
            print("Yes")
        else:
            print("No")
    elif len(a) == 3:
        if a[0][0] ^ a[1][0] ^ a[2][0] == 0:
            if a[0][1] == a[1][1] == a[2][1]:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        print("No")


if __name__ == '__main__':
    solve()

Solution (Python):
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
if True:
    for i in a[1:]:
      d[i] += 1
    now1,now2 = a[0],0
    for i in a[1:]:
      xor = now1^i
      d[i] -= 1
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = i, xor
        break
      d[i] += 1
      d[xor] += 1        
    else:
      print("No")
      exit()
    for i in range(n-3):
      xor = now1^now2
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = now2, xor
      else:
        print("No")
        exit()
    else:
      if now1^now2 == a[0]:
        print("Yes")
      else:
        print("No")
      exit()

Solution (Python):
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
if all([not i for i in a]):
    print("Yes")
else:
    for i in a[1:]:
      d[i] += 1
    now1,now2 = a[0],0
    ans = [now1]
    for i in a[1:]:
      xor = now1^i
      d[i] -= 1
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = i, xor
        ans.append(now1)
        ans.append(now2)
        break
      d[i] += 1
      d[xor] += 1        
    else:
      print("No")
      exit()
    for i in range(n-3):
      xor = now1^now2
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = now2, xor
        ans.append(now2)
        continue
      else:
        print("No")
        exit()
    else:
      if now1^now2 == a[0]:
        print("Yes")
      else:
        print("No")
      exit()

Solution (Python):
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
if all([not i for i in a]):
  print("Yes")
else:
  if n % 3:
    print("No")
  else:
    for i in a[1:]:
      d[i] += 1
    now1,now2 = a[0],0
    ans = [now1]
    for i in a[1:]:
      xor = now1^i
      d[i] -= 1
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = i, xor
        ans.append(now1)
        ans.append(now2)
        break
      d[i] += 1
      d[xor] += 1        
    else:
      print("No")
      exit()
    for i in range(n-3):
      xor = now1^now2
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = now2, xor
        ans.append(now2)
        continue
      else:
        print("No")
        exit()
    else:
      if now1^now2 == a[0]:
        print("Yes")
      else:
        print("No")
      exit()

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

    if A.count(0) == N:
        print("Yes")
    elif N % 3 == 0:
        A.sort()
        ans = True
        for i in range(N//3):
            if A[i] ^ A[i+(N//3)] != A[i+(N//3)*2]:
                ans = False
        if ans:
            print("Yes")
        else:
            print("No")
    else:
        print("No")



if __name__ == "__main__":
    main()

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

if len(b) != 3:
    if sum(a) == 0:
        pass
    elif a.count(max(b)) == 2*n/3 and a.count(0) == n/3:
        pass
    else:
        print("No")
        exit()
else:
    if b[0] ^ b[1] == b[2] and a.count(b[0]) == a.count(b[1]) == a.count(b[2]):
        print("Yes")
        exit()
    else:
        print("No")
        exit()
        
print("Yes")

Solution (Python):
n=int(input())
l=sorted(list(map(int,input().split())))
if len(set(l))==3:
  h=sorted(list(set(l)),reverse=1)
  ff=len(bin(h[0]))
  p=["0"*(ff-len(bin(s)))+bin(s)[2:] for s in h]
  y=p[0]
  dfg,dgf=p[1],p[2]
  for i in range(ff-2):
    q,w=dfg[i],dgf[i]
    if (q!=w and y[i]=="0") or (q==w and y[i]=="1"):print("No");exit()
  else:
    from collections import Counter as cou
    if len(set(cou(l).values()))==1:print("Yes")
    else:print("No")
elif len(set(l))>=4 or 0 not in set(l):
  print("No")
elif set(l)==set([0]):
  print("Yes")
else:
  if n%3:print("No");exit()
  from collections import Counter as cou
  fl,fll=0,0
  for g,gh in cou(l).items():
    if g==0 and gh==n//3:fl=1
    if g!=0 and gh==2*n//3:fll=1
  print("Yes" if fl and fll else "No")

Solution (Python):
import sys
from collections import Counter

N = int(input())
a = list(map(int,input().split()))
a.sort()
YES = 'Yes'
NO = 'No'
if a == [0]*N:
  print(YES)
  sys.exit()
  
if N%3 !=0:
  print(NO)
  sys.exit()
  
counter = Counter(a)
if len(counter) > 3:
  print(NO)
  sys.exit()
elif len(counter) == 3:
  if list(counter.values()) != [N//3,N//3,N//3]:
    print(NO)
  else:
    xor = 0
    for key in counter.keys():
      xor ^= key
    if xor == 0:
      print(YES)
    else:
      print(NO)
  sys.exit()
elif len(counter) == 2:
  if list(counter.keys())[0] == 0 and list(counter.values())[0] == N//3:
    print(YES)
  else:
    print(NO)
  sys.exit()

print(NO)

Solution (Python):
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    a = collections.Counter(a).most_common()
    if len(a) == 1:
        if a[0][0] == 0:
            print("Yes")
        else:
            print("No")
    elif len(a) == 2:
        if a[0][1] == a[1][1] * 2 and a[1][0] == 0:
            print("Yes")
        else:
            print("No")
    elif len(a) == 3:
        if a[0][0] ^ a[1][0] ^ a[2][0] == 0 and a[0][1] == a[1][1] == a[2][1]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")


if __name__ == '__main__':
    solve()

Solution (Python):
from collections import Counter
N=int(input())
a=list(map(int, input().split()))
flag=False
c=Counter(a)
if len(c.keys())==1:
  if 0 in c.keys():
    flag=True
elif len(c.keys())==2:
  if 0 in c.keys() and N%3==0:
    if c[0]*3==N:
      flag=True
elif len(c.keys())==3:
  x, y, z=c.keys()
  if c[x]==c[y] and c[y]==c[z] and x^y==z and N%3==0:
    flag=True
if flag:
  print("Yes")
else:
  print("No")

Solution (Python):
from collections import Counter
N=int(input())
a=list(map(int, input().split()))
flag=False
c=Counter(a)
if len(c.keys())==1:
  if 0 in c.keys():
    flag=True
elif len(c.keys())==2:
  if 0 in c.keys() and N%3==0:
    if c[0]*3==N:
      flag=True
elif len(c.keys())==3:
  x, y, z=c.keys()
  if c[x]==c[y] and c[y]==c[z] and x^y==z and N%3==0:
    flag=True
if flag:
  print("Yes")
else:
  print("No")

Solution (Python):
n=int(input())
def xor(x,y):
  bitx=[]
  bity=[]
  num1,num2=x,y
  while num1!=0:
    bitx.append(num1%2)
    num1//=2
  while num2!=0:
    bity.append(num2%2)
    num2//=2
  m=max(len(bitx),len(bity))
  while len(bitx)<m+1:
    bitx.append(0)
  while len(bity)<m+1:
    bity.append(0)
  ans=0
  for i in range(m):
    if bitx[i]!=bity[i]:
      ans+=2**i
  return ans
from collections import defaultdict
import sys
d=defaultdict(int)
l=list(map(int,input().split()))
if n%3!=0:
  for i in range(n):
    if l[i]!=0:
      print("No")
      sys.exit()
  print("Yes")
  sys.exit()
for i in l:
  d[i]+=1
if len(d)>3:
  print("No")
elif len(d)==3:
  b=True
  l1=[]
  for i in d:
    l1.append(i)
    if d[i]!=n/3:
      b=False
  if l1[0]!=xor(l1[1],l1[2]) or l1[1]!=xor(l1[0],l1[2]) or l1[2]!=xor(l1[0],l1[1]):
    b=False
  if b:
    print("Yes")
  else:
    print("No")
elif len(d)==2:
  if d[0]!=n/3:
    print("No")
  else:
    print("Yes")
else:
  if d[0]==n:
    print("Yes")
  else:
    print("No")

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

Solution (Python):

import sys
import collections

def main():
    n, *a = map(int, sys.stdin.read().split())

    c = collections.Counter(a)

    ans = 'No'
    if 0 in c:
        if c[0] == n:
            ans = 'Yes'
        elif c[0] == n / 3 and len(c) == 2:
            ans = 'Yes'

    else:
        if len(c) == 3:
            for i in c.values():
                if i != n / 3:
                    break
            else:
                b = list(c.keys())
                if b[0] ^ b[1] == b[2]:
                    ans = 'Yes'
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
b.sort()
if len(set(a))>=4:
    print('No')
elif b==[0]:
    print('Yes')
elif len(b)==2:
    c_1=a.count(0)
    c_2=a.count(b[1])
    if 2*c_1==c_2:
        print('Yes')
    else:
        print('No')
elif len(b)==3:
    c_1=a.count(b[0])
    c_2=a.count(b[1])
    c_3=a.count(b[2])
    if c_1==c_2==c_3 and b[0]^b[1]^b[2]==0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Solution (Python):
N = int(input())
aaa = sorted([int(i) for i in input().split()])

ans = 0
for a in aaa:
    ans = ans^a
if ans==0:
    print("Yes")
else:
    print("No")

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

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


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

if len(a)%3!=0:
  print("No")
else:
  if len(set(a))==2:
    aa=list(collections.Counter(a).items())
    aa.sort()
    if aa[0][0]==0 and aa[0][1]*2==aa[1][1]:
      print("Yes")
    else:
      print("No")
  elif len(set(a))==3:
    aa=list(collections.Counter(a).items())
    if aa[0][1]==aa[1][1]==aa[2][1] and aa[0][0]^aa[1][0]^aa[2][0]==0:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

Solution (Python):
from collections import Counter
n = int(input())
a = Counter(map(int,input().split()))
a = a.items()
a = sorted(a,key=lambda x: x[1],reverse=1)
if len(a) > 3:
  f = 1
elif len(a) == 3:
  b,c,d = a[0][0],a[1][0],a[2][0]
  if b^d != c or c^b != d or d^c != b:
    f = 1
  elif a[0][1] == a[1][1] == a[2][1]:
    f = 0
  else:
    f = 1
elif len(a) == 2:
  b,c,d = a[0][0],a[0][0],a[1][0]
  if b^d != c or c^b != d:
    f = 1
  elif a[0][1] == 2*a[1][1]:
    f = 0
  else:
    f = 1
else:
  b,c,d = a[0][0],a[0][0],a[0][0]
  if b^d != c:
    f = 1
  else:
    f = 0
print('YNeos'[f::2])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
if len(b)>3:
  print("No")
elif len(b)==3:
  if b[0]^b[1]^b[2]==0:
    if a.count(b[0])==a.count(b[1]) and a.count(b[1])==a.count(b[2]):
      print("Yes")
    else:
      print("No")
  else:
    print("No")
elif len(b)==2:
  b=sorted(b)
  if b[0]==0:
    if a.count(b[0])==n//3 and a.count(b[1])==2*n//3:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
else:
  if b[0]==0:
    print("Yes")
  else:
    print("No")

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
dic = {}
a.sort()
for i in a:
    if (i in dic):
        dic[i] += 1
    else:
        dic[i] = 1

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):
    l = list(dic.keys())
    if (l[0]^l[1]^l[2] == 0):
        v = list(dic.values())
        if (v[0] == v[1])&(v[1] == v[2])&(v[2] == n/3):
            print("Yes")
        else:
            print("No")
    else :
        print("No")
else:
    print("No")