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()))

from collections import Counter

c = Counter(a)

if c[0] > 0:
    if len(c) == 1:
        bl = True
    else:
        if len(c) > 2:
            bl = False
        else:
            bl = (n == 3 * c[0])
else:
    se = set(c.keys())
    if len(se) != 3:
        bl = False
    else:
        bl = True
        xor = 0
        for key in se:
            xor ^= key
            if c[key] * 3 != n:
                bl = False
        if xor != 0:
            bl = False

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

Solution (Python):
N = int(input())
arr = list(map(int, input().split()))
cnt = arr.count(0)
if cnt == N:
    print('Yes')
    exit()
if N % 3 != 0:
    print('No')
    exit()
if cnt == N//3 and len(set(arr)) == 2:
    print('Yes')
    exit()
from collections import defaultdict
d = defaultdict(int)
for i in arr:
    d[i] += 1
if len(d) != 3:
    print('No')
    exit()
check = []
for key in d.keys():
    check.append(key)
if d[check[0]] == d[check[1]] and d[check[1]] == d[check[2]] and d[check[2]] == d[check[0]] and check[0]^check[1]^check[2] == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

import copy






INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n = ni()
    a = na()

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

    
    c = collections.Counter(a)
    if n % 3 == 0:
        if 0 in c.keys() and len(c) == 2:
            if n // 3 == c[0]:
                print("Yes")
                exit(0)

    

    t_key=[]
    t_value=[]
    if len(c) == 3:
        for k,v in c.items():
            t_key.append(k)
            t_value.append(v)
    else:
        print("No")
        exit(0)


    if t_key[0] ^ t_key[1] ^ t_key[2] == 0 and t_value[0]==t_value[1]==t_value[2]==n//3:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
N = int(input())
a = Counter(list(map(int, input().split())))
b = set(a.values())
if a[0] == N:
    print('Yes')
elif N % 3 == 0:
    if len(b) == 1:
        c = [x for x in a.keys()]
        if len(c) == 3:
            if c[0] ^ c[1] ^ c[2] == 0:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    elif len(b) == 2:
        if a[0] == N // 3:
            if (N*2) // 3 in b:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Solution (Python):
import sys
from collections import defaultdict, deque, Counter





stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())
a = list(map(int, stdin.readline().rstrip().split()))



check = set(a)
coll = Counter(a)

if check == {0}:
    print("Yes")
elif len(check) == 3:
    if list(check)[0] ^ list(check)[1] ^ list(check)[2] == 0:
        if coll[list(check)[0]] == coll[list(check)[1]] == coll[list(check)[2]]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(list(check)) == 2:
    if list(check)[0] == 0:
        if coll[list(check)[0]] * 3 == n:
            print("Yes")
        else:
            print("No")
    elif list(check)[1] == 0:
        if coll[list(check)[0]] * 3 == n:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
if sum(a)==0:
    print('Yes')
    exit()
x=[0]*3
x[0] = a.count(a[0])
x[1] = a.count(a[n//2])
x[2] = a.count(a[-1])
x.sort()

if a[0]^a[n//2] == a[-1] and x[0] == x[1] == x[2] == n//3:
    print('Yes')
elif a[0] == 0 and x[0] == n//3 and x[1] == x[2] == n*2//3:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys
input = sys.stdin.readline
from collections import Counter
def judge(vals):
    return vals[0] ^ vals[1] ^ vals[2] == 0
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = "No"
    c = Counter(A)
    con1 = len(c) == 2 and c[0] * 3 == N
    items = list(c.items())
    con2 = len(c) == 3 and items[0][1] * 3 == N and items[1][1] * 3 == N and judge(list(c.keys()))
    con3 = c[0] == N
    if con1 or con2 or con3:ans = "Yes"
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N = int(input())
    A = [int(_) for _ in input().split()]
    xor = 0
    for a in A:
        xor ^= a
    print('No' if xor else 'Yes')
    return

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())

a = list(map(int,input().split()))
a.sort()
d = {}
for i in range(n):
    if(a[i] not in d):d[a[i]] = 1
    else:d[a[i]] += 1
if(len(d) == 1):
    if(a[0] == 0):
        print('Yes')
        exit()
elif(n%3 == 0):
    if(len(d) == 2):
        if(0 in d):
            if(d[0] == n // 3):
                print('Yes')
                exit()
    elif(len(d) == 3):
        k = list(d.keys())
        if(k[0]^k[1]^k[2] == 0):
            if(d[k[0]] == n // 3 and d[k[1]] == n // 3 and d[k[2]] == n // 3):
                print('Yes')
                exit()
print('No')

Solution (Python):

"""
問題：
円環状にリストの数値を配置した時、aのどの要素についても
ai == a(i-1)^a(i+1)
となるように配置できるか判定せよ
解法：
できるかどうかを判定すればよいので実際に組み立てる必要はない。
n<=10**5であることから、選び方を考えなくて良い解法が存在するはず
全てのXORの合計が0?
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))

ans = 0
for i in lst1:
    ans = ans^i

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

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

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

import collections
dic=dict(collections.Counter(A))
li=list(dic.values())

ans='No'

if len(li)==3:
    if N%3 == 0:
        x,y,z = dic.keys()
        if li[0]== N//3 and li[1]==N//3 and x^y== z:
            ans='Yes'           
elif len(li)==2:
    if N%3 == 0:
        if li[0]== 2*N//3 or li[1]==2*N//3:
            ans='Yes'
elif len(li)==1:
        if list(dic.keys())[0]==0:
            ans='Yes'

print(ans)

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

import collections
dic=dict(collections.Counter(A))
li=list(dic.values())

ans='No'

if len(li)==3:
    if N%3 == 0:
        x,y,z = dic.keys()
        if li[0]== N//3 and li[1]==N//3 and x^y^z == 0:
            ans='Yes'           
elif len(li)==2:
    if N%3 == 0:
        if li[0]== 2*N//3 or li[1]==2*N//3:
            ans='Yes'
elif len(li)==1:
        if list(dic.keys())[0]==0:
            ans='Yes'

print(ans)

Solution (Python):

import sys
from collections import Counter

def main():
    N = int(input())
    a = list(map(int, input().split()))
    l = Counter(a)
    if len(l)==1 and 0 in l:
        print('Yes')
        exit()
    if N%3==0 and len(l)==2 and 0 in l and l[0] == N//3:
        print('Yes')
        exit()
    if N%3==0 and len(l)==3:
        x,y,z = l.keys()
        if l[x] == l[y] == N//3 and x^y^z == 0:
            print('Yes')
            exit()
    print('No')

    

if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())
import collections
a_frq_dict = collections.Counter(map(int, input().split(' ')))

n = len(a_frq_dict)

if n == 1:
    if a_frq_dict[0]:
        print('Yes')
        exit()

elif n == 2:
    if N % 3 == 0 and a_frq_dict[0] == (N//3):
        print('Yes')
        exit()

elif n == 3:
    if N % 3 == 0:
        if all([f == (N//3) for f in a_frq_dict.values()]):
            values = list(a_frq_dict.keys())
            v = values[0] ^ values[1] ^ values[2]
            if v == 0:
                print('Yes')
                exit()

print('No')

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

ans = "No"
if c0==n: ans = "Yes"
elif len(set(a)) == 2:
    c = a.count(a[-1])
    if c == (2*n)//3 and c0 == n//3: ans = "Yes"
elif len(set(a)) == 3:
    x,y,z = list(set(a))
    if a.count(x) == a.count(y) == a.count(z):
        if int(bin(x ^ y ^ z),2) == 0: ans = "Yes"
print(ans)

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

c = Counter(A)
n = len(c)
if ((n == 1 and c[0] > 0)
        or (n == 2 and c[0] == N//3)):
    print('Yes')
elif n == 3:
    x, y, z = c.keys()
    if x ^ y ^ z == 0 and all(n == N // 3 for n in c.values()):
        print('Yes')
    else:
        print('No')
else:
    print('No')

Solution (Python):

import sys
from collections import Counter

def main():
    N = int(input())
    a = list(map(int, input().split()))
    l = Counter(a)
    if len(l)==1 and 0 in l:
        print('Yes')
        exit()
    if N%3==0 and len(l)==2 and 0 in l and l[0] == N//3:
        print('Yes')
        exit()
    if N%3==0 and len(l)==3:
        x,y,z = l.keys()
        if l[x] == l[y] == N//3 and x^y^z == 0:
            print('Yes')
            exit()
    print('No')

    

if __name__ == '__main__':
    main()

Solution (Python):

import sys
from collections import Counter

def main():
    N = int(input())
    a = list(map(int, input().split()))
    l = Counter(a)
    if len(l)==1 and 0 in l:
        print('Yes')
        exit()
    if N%3==0 and len(l)==2 and 0 in l and l[0] == N//3:
        print('Yes')
        exit()
    if N%3==0 and len(l)==3:
        x,y,z = l.keys()
        if l[x] == l[y] == N//3 and x^y^z == 0:
            print('Yes')
            exit()
    print('No')

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())

A = list(map(int,input().split()))
from collections import Counter

for a in A:
  if a != 0:
    break
else:
  print('Yes')
  exit()

A = list(Counter(A).most_common())

if len(A) == 2 and A[1][0]==0 and A[1][1] == n//3:
  print('Yes')
  exit()

B = []
for a,c in A:
  if c != n//3:
    print('No')
    exit()
  B.append(a)
n = len(str(max(B)))
  
B = [[(1<<j&i)>>j for j in range(30)] for i in B]
for i in range(30):
  if B[0][i]^B[1][i]^B[2][i] != 0:
    print('No')
    break
else:
  print('Yes')

Solution (Python):
n = int(input())
a = sorted(list(map(int,input().split())))
c0 = a.count(0)
ans = 'No'
if c0==n:
    ans = 'Yes'
if len(set(a))==2:
    c = a.count(a[-1])
    if c==n*2/3 and c0==n/3:
        ans = 'Yes'
if len(set(a))==3:
    s = 0
    f = True
    for i in set(a):
        s ^= i
        if a.count(i)!=n/3:
            f = False
    if f and s==0:ans='Yes'
print(ans)

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(set(a)))
l=len(b)
if l>=4:
    print("No")
    exit()
else:
    if l==1:
        if b[0]==0:
            print("Yes")
        else:
            print("No")
    elif l==2:
        if n%3!=0:
            print("No")
        else:
            if b[0]!=0:
                print("No")
            else:
                cnt1=a.count(b[0])
                cnt2=a.count(b[1])
                if cnt2==(n//3)*2:
                    print("Yes")
                else:
                    print("No")
    else:
        if n%3!=0:
            print("No")
        else:
            cnt1=a.count(b[0])
            cnt2=a.count(b[1])
            cnt3=a.count(b[2])
            if cnt1!=n//3 or cnt2!=n//3 or cnt3!=n//3:
                print("No")
            else:
                if b[0]^b[2]!=b[1]:
                    print("No")
                else:
                    print("Yes")

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

from collections import Counter

c = Counter(a)

if c[0] == N:
    print('Yes')
    exit()
if N % 3 != 0:
    print('No')
    exit()
if c[0] == N//3 and len(c) == 2:
    print('Yes')
    exit()
if len(c) != 3:
    print('No')
    exit()
A = list(c.values())
if not (A[0] == N//3 and A[1] == N//3 and A[2] == N//3):
    print('No')
    exit()
B = list(c.keys())
if B[0]^B[1] != B[2]:
    print('No')
    exit()
print('Yes')

Solution (Python):
from collections import Counter

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


D = Counter(A)
A = set(A)
if len(A) == 1 and 0 in A:
	print("Yes")
elif len(A) == 2 and 0 in A and n % 3 == 0:
	for k, v in D.items():
		if k != 0:
			cnt_else = v
		
	if cnt_else == n * 2 // 3:
		print("Yes")
	else:
		print("No")
elif len(A) == 3 and n % 3 == 0:
	if len(set(D.values())) == 1:
		A = list(A)
		if A[0] ^ A[1] ^ A[2] == 0:
			print("Yes")
		else:
			print("No")
	else:
		print("No")		
else:
	print("No")

Solution (Python):
from sys import stdin


def main():
    _ = int(input())
    a_lists = [int(x) for x in stdin.readline().rstrip().split()]
    z = 0

    for a in a_lists:
        z ^= a

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


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *a = map(int, read().split())
for af in a[1:]:
    a[0] ^= af
print('Yes' if a[0] == 0 else 'No')

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

x=len(set(A))
if x==1:
  if A==[0]*N:
    print('Yes')
  else:
    print('No')
elif x==2:
  B=list(set(A))
  a,b=max(B),min(B)
  if b==0 and A.count(0)==(N//3):
    print('Yes')
  else:
    print('No')
elif x==3:
  B=list(set(A))
  a=max(B)
  c=min(B)
  b=sum(B)-a-c
  if A.count(a)==A.count(b) and A.count(b)==A.count(c):
    if a^b==c:
      print('Yes')
    else:
      print('No')
  else:
    print('No')
else:
  print('No')

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

a=A[0]
for i in range(N-1):
  a=a^A[i+1]
if a==0:
  print("Yes")
else:
  print("No")

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = sorted(na())
x = [[0]*n for _ in range(30)]
 
if n%3:
    if max(a):
        print("No")
    else:
        print("Yes")
else:
    m = n//3
    if a[0] == a[m-1] and a[m] == a[2*m-1] and a[2*m] == a[3*m-1] and a[0]^a[m] == a[2*m]:
        print("Yes")
    else:
        print("No")

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
Ad = {}
for a in A:
  if a not in Ad:
    Ad[a] = 1
  else:
    Ad[a] += 1
a = len(Ad)
if a == 1:
  for i in Ad.keys():
    if i == 0:
      print('Yes')
    else:
      print('No')
elif n % 3:
  print('No')
elif a == 2:
  x = 0
  for k,v in Ad.items():
    if v != n//3 and v != n//3*2:
      print("No")
      break
    else:
      x ^= k
      if v == n//3*2:
        x ^= k
  else:
    if x == 0:
      print('Yes')
    else:
      print('No')
elif a == 3:
  x = 0
  for k,v in Ad.items():
    if v != n//3:
      print("No")
      break
    else:
      x ^= k
  else:
    if x == 0:
      print('Yes')
    else:
      print('No')
else:
  print('No')

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

now=A[0]
for i in range(1,N):
    now=now^A[i]

if now==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 and len(c) == 2:
    for A in a:
        if c[A] == (2*N)//3:
            print("Yes")
            break
    else:
        print("No")
elif N%3 == 0 and len(c) == 3:
    tmp = list(set(a))
    if c[tmp[0]] == c[tmp[1]] == c[tmp[2]] and tmp[0] ^ tmp[1] ^ tmp[2] == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]

res = a[0]
for i in range(1,n):
    res = res^a[i]
if res == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter

def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    ac=Counter(A)
    aci=list(ac.items())
    aci.sort()
    ans="No"
    if aci[0]==(0,n):
        ans="Yes"
    elif n%3==0 and len(aci)==2:
        if aci[0]==(0,n//3) and aci[1][1]==n//3*2:
            ans="Yes"
    elif n%3==0 and len(aci)==3:
        if aci[0][1]==aci[1][1] and aci[1][1]==aci[2][1] and aci[0][0]^aci[1][0]^aci[2][0]==0:
            ans="Yes"  
    print(ans)


if __name__=='__main__':
    main()

Solution (Python):
n, *a = map(int, open(0).read().split())

set_a = set(a)
set_a = sorted(set_a)

ans = 'No'

if len(set_a) == 1 and a[0] == 0:
    ans = 'Yes'

if len(set_a) == 2 and n%3 == 0 and a.count(0) == n//3 and a.count(set_a[1]) == 2*n//3:
    ans = 'Yes'

if len(set_a) == 3 and n%3 == 0:
    if set_a[0] ^ set_a[1] ^ set_a[2] == 0:
        ans = 'Yes'
        for i in range(3):
            if a.count(set_a[i]) != n//3:
                ans = 'No'
                break
print(ans)

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

def print_yes():
    print('Yes')
    exit(0)

def print_no():
    print('No')
    exit(0)

if not any(a):
    print('Yes')
else:
    if N % 3 == 0:
        counter = Counter(a)
        
        if len(counter) == 3:
            for i in counter.values():
                if i != N / 3:
                    print_no()
            if reduce(lambda a,b: a^b, list(counter.keys())) == 0:
                print_yes()
            else:
                print_no()
        elif len(counter) == 2:
            if a.count(0) == N/3:
                print_yes()
            else:
                print_no()
        else:
            print_no()
    else:
        print_no()

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

if len(num) == 1 and num[0] == 0:
    print('Yes')
elif N % 3 == 0:
    if len(num) == 3:
        s = a.count(num[0])
        t = a.count(num[1])
        u = a.count(num[2])
        if s == t and t == u and u == s and num[0] ^ num[1] == num[2]:
            print('Yes')
        else:
            print('No')
    elif len(num) == 2:
        if a.count(max(num)) == a.count(0) * 2:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Solution (Python):
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
a_set = set(a)

if len(a_set)==1:
    if sum(a_set)==0:
        print('Yes')
    else:
        print('No')
elif len(a_set)==2:
    a_1,a_2 = sorted(a_set)
    if a_1==0:
        if a.count(a_1)*3==n:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(a_set)==3:
    a_1,a_2,a_3= a_set
    if a.count(a_1)==a.count(a_2) and a.count(a_2)==a.count(a_3):
        if a_1^a_2==a_3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

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

Solution (Python):
import sys
from sys import stdin

n = int(stdin.readline().rstrip())
a = list(map(int, stdin.readline().rstrip().split()))
tmp = a[0]
for i in range(1, len(a)):
    tmp = tmp ^ a[i]
for i in range(1, len(a)):
    if a[i] ^ tmp == a[i]:
        print('Yes')
        sys.exit()
print('No')

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
if n%3==0:
  d={}
  for ai in a:
    if ai not in d:
      d[ai]=a.count(ai)
      if len(d)==4:
        break
  sa=list(set(a))
  if len(sa)==3 and sa[0]^sa[1]==sa[2] and d[sa[0]]==d[sa[1]] and d[sa[0]]==d[sa[2]]:
    print('Yes')
    exit()
  if len(sa)==2 and 0 in d and 2*d[0]==max(d[sa[0]],d[sa[1]]):
    print('Yes')
    exit()

if n == a.count(0):
  print('Yes')
  exit()

print('No')

Solution (Python):
input()
a=[int(i) for i in input().split()]
ans=0
for i in a:
  ans^=i
print('Yes' if ans==0 else 'No')

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

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

cnt = {}
for a in A:
    if a not in cnt:
        cnt[a] = 1
    else:
        cnt[a] += 1

if len(cnt) == 2:
    if cnt[0] == N // 3:
        print("Yes")
        exit(0)

if len(cnt) == 3:
    k1, k2, k3 = cnt.keys()
    v1, v2, v3 = cnt.values()
    if not (k1 ^ k2 ^ k3):
        if v1 == v2 and v2 == v3:
            print("Yes")
            exit(0)

print("No")

Solution (Python):

from collections import Counter, deque  













import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


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

        if all(a == 0 for a in A):
            return True
        if N % 3 != 0:
            return False

        AA = Counter(A)
        if len(AA) == 2:
            AAA = AA.most_common()
            if AAA[0][1] != N * 2 // 3:
                return False
            return AAA[1][0] == 0

        if len(AA) == 3:
            if any(v != N // 3 for v in AA.values()):
                return False
            k1, k2, k3 = AA.keys()
            return k1 ^ k2 == k3 or k1 ^ k3 == k2 or k2 ^ k3 == k1

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


resolve()

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
from collections import Counter
cntr = Counter(A)
ans = 'No'
if len(set(A)) == 1 and A[0] == 0:
  ans = 'Yes'
elif n % 3 == 0:
  if len(cntr) == 3:
    k = list(cntr.keys())
    v = list(cntr.values())
    if k[0]^k[1]^k[2] == 0 and v[0] == v[1] and v[1] == v[2]:
      ans = 'Yes'
  elif len(cntr) == 2:
    if sorted(cntr.keys())[0] == 0 and cntr.get(0) == n//3:
      ans = 'Yes'
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
c = list(b.items())
if all(i==0 for i in a):
    print("Yes")
elif len(b)==2 and n%3==0 and b[0]==n//3:
    print("Yes")
elif len(b)==3 and c[0][0]^c[1][0]^c[2][0]==0 and c[0][1]==c[1][1]==c[2][1]:
    print("Yes")
else:
    print("No")

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

Solution (Python):
from collections import Counter,OrderedDict

N=int(input())
a=list(map(int,input().split()))
d=OrderedDict(Counter(a))
e=list(d)
e.sort()

if len(d)>3:
    ans="No"
else:
    ans="No"
    if len(d)==1:
        if e[0]==0:
            ans="Yes"
    elif len(d)==2:
        if N%3==0:
            if e[0]==0 and d[0]==N//3 and d[e[1]]==2*N//3:
                ans="Yes"
    else:
        if N%3==0:
            if d[e[0]]==d[e[1]]==d[e[2]]:
                if e[0]^e[1]^e[2]==0:
                    ans="Yes"
                   
print(ans)

Solution (Python):
from collections import Counter

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

if 0 in ca and ca[0] == n:
    print("Yes")
elif n % 3 == 0 and 0 in ca and ca[0] == n // 3 and len(ca) == 2:
    print("Yes")
elif n % 3 == 0 and len(ca) == 3:
    values = []
    for c in ca:
        if ca[c] == n // 3:
            values.append(c)
    
    if len(values) != 3:
        print("No")
    else:
        ans = 0
        for k in values:
            ans ^= k
        if ans == 0:
            print("Yes")
        else:
            print("No")
else:
    print("No")

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n = onem()

a = l()

a.sort()

a = s(a)

if len(a) == 1:
    if a[0][0] == 0:
        print("Yes")
        exit()
elif len(a) == 2:
    if a[0][0] == 0:
        if a[0][1] == n//3 and a[1][1] == (2*n)//3:
            print("Yes")
            exit()

elif len(a) == 3:
    if not (a[0][0] ^ a[1][0] ^ a[2][0]):
        if (a[0][1] == n//3 and a[1][1] == n//3 and a[2][1] == n//3):
            print("Yes")
            exit()
            
print("No")

Solution (Python):


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

if max(nums) == 0:
    print('Yes')
    exit()

if n % 3:
    print('No')
    exit()

m = n // 3
nums.sort()
for i in range(m-1):
    if nums[i] != nums[i+1] or nums[m+i] != nums[m+i+1] or nums[2*m+i] != nums[2*m+i+1]:
        print('No')
        exit()

if nums[0] ^ nums[m] == nums[2*m]:
    print('Yes')
else:
    print('No')

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=a[1]
for i in range(2,n):
    b = b^(a[i])

if b==a[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, radians
from itertools import accumulate, permutations, combinations, 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
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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

N = INT()
a = LIST()

xor = lambda x, y: x^y
ret = reduce(xor, a)
print("No" if ret else "Yes")

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

xor=0

for i in range(n):
    xor=xor^a[i]
if xor==0:
    print("Yes")
else:
    print("No")

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(n):
  s ^= a[i]
if s == 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 len(c) > 3:
    print('No')
else:
    if len(c) == 1 and c.get(0):
        print('Yes')
    elif len(c) == 2 and c.get(0) == n / 3:
        print('Yes')
    elif len(c) == 3:
        x, y, z = c.keys()
        if x^y^z == 0 and c.get(x) == c.get(y) == c.get(z) == n / 3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

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

Solution (Python):
import collections
N=int(input())
a=list(map(int,input().split()))
l=[]
if max(a)==0:
    print("Yes")
elif (N%3)==0:
    c=collections.Counter(a)
    values = list(c.values())  
    key = list(c.keys())  
    for i in range(len(key)):
        l.append([key[i], values[i]])  
    l.sort(key=lambda x:x[1],reverse=True)
    
    if (len(l)==3)and(l[0][1]==l[1][1]==l[2][1])and(l[0][0]^l[1][0]==l[2][0]):
        print("Yes")
    elif (len(l)==2)and(l[0][1]==2*l[1][1])and(l[1][0]==0):
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

n = int(input())
a = list(map(int, input().split()))
for i in range(1, n):
  a[i] ^= a[i - 1]
if a[n - 1] == 0:
  print('Yes')
else:
  print('No')