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 collections
N = int(input())
a = list(map(int,input().split()))
B = collections.Counter(a)
k = list(B.keys())
v = list(B.values())

ans = "Yes"
if len(B) == 3 and k[0]^k[1]^k[2] == 0 and v[0] == v[1] == v[2]: pass
elif len(B) == 2 and 0 in k and (v[0] == 2*v[1] or v[1] == 2*v[0]): pass
elif len(B) == 1 and 0 in k: pass
else: ans = "No"
print(ans)

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

judge = False
if 0 in c and c[0] == n:
  judge = True
if n % 3 == 0:
  judge1, judge2 = False, 0
  num = 0
  value = 0
  for k, v in c.items():
    num += 1
    if v == n // 3:
      if k == 0:
        judge1 = True
      judge2 += 1
    value ^= k
  if judge1 and num == 2:
    judge = True
  if judge2 == num == 3 and value == 0:
    judge = True

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

Solution (Python):
import sys
import itertools

import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

def solve(N,A):
    if all(x == 0 for x in A):
        return True
    q,r = divmod(N,3)
    if r:
        return False
    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
    return False
print('Yes' if solve(N, A) else 'No')

Solution (Python):





N = int(input())
A = list(map(int, input().split()))
n = N // 3
dic = {}

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = True

if len(dic) > 3:
    ans = False

elif len(dic) == 3:
    keys = dic.keys()
    t = []
    for k in keys:
        t.append(k)
        if dic[k] != n:
            ans = False

    a = t[0]
    b = t[1]
    c = t[2]

    if (a ^ b) != c:
        ans = False

elif len(dic) == 2:
    for k in dic:
        if k == 0:
            if dic[k] != n:
                ans = False
        else:
            if dic[k] != n * 2:
                ans = False

else:
    keys = dic.keys()
    if not 0 in keys:
        ans = False

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

Solution (Python):
from collections import*
n,*A=map(int,open(0).read().split());C=Counter(A).items();f=1;l=len(C)
if l==3:
  x=0
  for c in C:x^=c[0]
  f=(len(set(c[1]for c in C))>1)+n%3+x>0
elif l==2:f=(abs(sum(c[1]*(-1)**i for i,c in enumerate(C)))!=n//3)+n%3>0
else:f=(l!=1)+A[0]>0
print('YNeos'[f::2])

Solution (Python):
N = int(input())
nums =list(map(int, input().split()))
a = {}
INF = 10**5
for num in nums:
  if not num in a:
    a[num] = 1
  else:
    a[num] += 1
  if len(a) > 3:
    print('No')
    exit()
def same_count(dic):
  v_max = 0
  v_min = INF
  for v in dic.values():
    v_max = max(v_max, v)
    v_min = min(v_min, v)
  return v_max == v_min
def xor_zero(dic):
  a = 0
  for k in dic.keys():
    a ^= k
  return True if a == 0 else False

def double_count(dic):
  v_max = 0
  v_min = INF
  for v in dic.values():
    v_max = max(v_max, v)
    v_min = min(v_min, v)
  return v_max == v_min*2 and dic[0] == v_min

answer = False
if len(a) == 3:
  answer = same_count(a) and xor_zero(a)
elif len(a) == 2:
  answer = 0 in a.keys() and double_count(a)
elif len(a) == 1:
  answer = 0 in a.keys()
if answer:
  print('Yes')
else:
  print('No')

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

if N % 3 != 0:
    res = 'Yes'
    for i in range(N):
        if a_ls[i] != 0:
            res = 'No'
else:
    res = 'Yes'
    c = Counter(a_ls)
    if len(c) > 3:
        res = 'No'
    if len(c) == 3:
        if not list(c.values())[0] == list(c.values())[1] == list(c.values())[2]:
            res = 'No'
        for i in c.keys():
            for j in c.keys():
                for k in c.keys():
                    if i!=j and j!=k and k!=i and not i^j==k:
                        res = 'No'
    elif len(c) == 2:
        if not (list(c.values())[0] == N//3 or list(c.values())[1] == N//3):
            res = 'No'
        if list(c.values())[0] == N//3:
            if not list(c.keys())[0] == 0:
                res = 'No'
        if list(c.values())[1] == N//3:
            if not list(c.keys())[1] == 0:
                res = 'No'
    else:
        for i in range(N):
            if a_ls[i] != 0:
                res = 'No'
        
print(res)

Solution (Python):
from collections import Counter

N = int(input())

A = list(map(int, input().split()))
c = Counter(A)
a = list(set(A))


if len(a) >= 4:
    ans = False

elif len(a) == 3:
    a, b, d = a
    if c[a] == c[b] and c[b] == c[d] and a^b == d and d^b == a and a^d == b:
        ans = True
    else:
        ans = False

elif len(a) == 2:
    a, b = sorted(a)
    if a == 0 and c[a] == N/3 and c[b] == (N/3)*2:
        ans = True
    else:
        ans = False

elif len(a) == 1:
    if sum(a) == 0:
        ans = True
    else:
        ans = False

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

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

flag=False
if sum(a)==0:
    flag=True
elif N%3==0:
    if len(a_set)==2:
        x,y=a_set
        if x==0 and a.count(x)*3==N:
            flag=True
    elif len(a_set)==3:
        x,y,z=a_set
        if x^y^z==0 and a.count(x)==a.count(y) and a.count(y)==a.count(z):
            flag=True

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

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

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

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


x=list(set(a))

z=[]

if len(x)>3:
  print('No')
  exit()

for i in x:
  if a.count(i)==n//3:
    z+=[i]
  
  elif a.count(i)==(n//3)*2:
    z+=[i]
    z+=[i]

  elif a.count(i)==n:
    z+=[i]
    z+=[i]
    z+=[i]

  else:
    print('No')
    exit()


ans=0

for i in z:
  ans^=i

if ans==0:
  print('Yes')

else:
  print('No')

Solution (Python):
def get_caps(a):
  dic = dict()

  for ai in a:
    dic.setdefault(ai, 0)
    dic[ai] += 1

  return dic


def is_match(caps):
  global N

  if 0 in caps.keys():
    if caps[0] == N:
      return True
  
  if N % 3 == 0:
    if 0 in caps.keys() and len(caps) == 2:
      if caps[0] == N//3:
        return True
    elif len(caps) == 3:
      x, y, z = caps.keys()
    
      if x ^ y ^ z == 0:
        if caps[x] == caps[y] == caps[z] == N//3:
          return True



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


caps = get_caps(a)

if is_match(caps):
  print('Yes')
else:
  print('No')

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
if sum(a)==0:
  print('Yes')
else:
  if n%3!=0:
    print('No')
  else:
    s = len(set(a))
    if s>3:
      print('No')
    else:
      l = Counter(a)
      tf = 1
      if s==3:
        for v in l.values():
          if v!=n//3:
            tf = 0
        li = list(set(a))
        if li[0]^li[1]^li[2]!=0:
          tf = 0
      elif s==2:
        if 0 not in l.keys():
          tf = 0
        else:
          for k in l.keys():
            if k==0 and l[k]!=n//3:
              tf = 0
      else:
        tf = 0
      print('Yes' if tf else 'No')

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

d = defaultdict(int)

for i in a:
  d[i] += 1

a.sort()
if max(a) == 0 and min(a) == 0:
  print ('Yes')
  exit()
b = set(a)
if len(b) == 3:
  c = 0
  for i in b:
    c ^= i
  if c == 0:
    flg = 0
    for i in d:
      if d[i] != n/3:
        flg = 1
    if flg == 1:
      print ('No')
    else:
      print ('Yes')
  else:
    print ('No')
  exit()
else:
  if min(a) == 0 and d[min(a)] ==n/3 and d[max(a)] == (2*n)/3:
    print('Yes')
  else:
    print ('No')
  exit()
print ('No')

Solution (Python):
N=int(input())
a_list=list(map(int,input().split()))
a_set=set(a_list)
if len(a_set)==1:
    if sum(a_set)==0:
        print("Yes")
    else:
        print("No")
elif len(a_set)==2:
    a_1, _=sorted(a_set)
    if a_1==0:
        if a_list.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_list.count(a_1)==a_list.count(a_2) and a_list.count(a_2)==a_list.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()))
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict 
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  
  
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  






C=Counter(A)
NUM=[]
if n%3!=0:
    if len(C)!=1 or A[0]!=0:
        print("No");exit()
    else:
        print("Yes");exit()
if all([i%(n//3)==0 for i in C.values()]):
    for i,v in C.items():
        if v==n//3:
            NUM.append(i)
        if v==n*2//3:
            NUM.append(i)
            NUM.append(i)
        if v==n:
            if i==0:print("Yes");exit()
            print("No");exit()
    a,b,c=NUM
    print("Yes" if a^b==c else "No");exit()
print("No")

Solution (Python):
from collections import Counter

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

cnt = Counter(A)

if len(cnt) == 1:
    if cnt[0] == n:
        print('Yes')
    else:
        print('No')
elif len(cnt) == 2:
    if cnt[0] == n/3:
        print('Yes')
    else:
        print('No')
elif len(cnt) == 3:
    test = 0
    for p in cnt.keys():
        if cnt[p] != n/3:
            print('No')
            break
        test ^= p
    else:
        if not test:
            print('Yes')
        else:
            print('No')
else:
    print('No')

Solution (Python):
from collections import Counter

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

k, v = list(Counter(a).keys()), list(Counter(a).values())
if len(k) == 3 and k[0] ^ k[1] == k[2] and v[0] == v[1] == v[2] :
    print('Yes')
elif len(k) == 2 and ((k[0] == 0 and v[0] * 2 == v[1]) or (k[1] == 0 and v[1] * 2 == v[0])) :
    print('Yes')
elif len(k) == 1 and k[0] == 0 :
    print('Yes')
else :
    print('No')

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

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

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


x=list(set(a))

z=[]

if len(x)>3:
  print('No')
  exit()

for i in x:
  if a.count(i)==n//3:
    z+=[i]
  
  elif a.count(i)==(n//3)*2:
    z+=[i]
    z+=[i]

  elif a.count(i)==n:
    z+=[i]
    z+=[i]
    z+=[i]

  else:
    print('No')
    exit()


ans=0

for i in z:
  ans^=i

if ans==0:
  print('Yes')

else:
  print('No')

Solution (Python):
n=int(input())
a=sorted(list(map(int, input().split(" "))))
if sum(a) == 0:
  print("Yes")
elif n % 3 != 0:
  print("No")
else:
  ass = [a[0], a[n // 3], a[n // 3 * 2]]
  
  if a.count(ass[0]) % (n // 3) != 0 or a.count(ass[1]) % (n // 3) != 0 or a.count(ass[2]) % (n // 3) != 0:
    print("No")
  else:
    if ass[0] ^ ass[1] != ass[2]:
      print("No")
    else:
      print("Yes")

Solution (Python):
from collections import defaultdict
def main3():
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort()

    c = defaultdict(int)
    for a in A:
        c[a] += 1

    if len(c) == 1:
        n = list(c.keys())
        if n[0] == 0:
            print("Yes")
        else:
            print("No")
    
    elif len(c) == 2:
        n = list(c.keys())
        if n[0] == 0 and c[n[1]] == 2*c[n[0]]:
            print("Yes")
        else:
            print("No")
    
    elif len(c) == 3:
        n = list(c.keys())

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

if __name__ == "__main__":
    main3()

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    a = LI()
    cnt = collections.Counter(a)
    kind = len(cnt)

    ans = False
    if kind == 1:
        ans |= a[0] == 0
    elif kind == 2:
        key = list(cnt.keys())
        value = list(cnt.values())
        if 0 in key:
            x = key[0]^key[1]
            ans = cnt[0]*2 == cnt[x]
    elif kind == 3:
        key = list(cnt.keys())
        value = list(cnt.values())
        ans = True
        ans &= key[0]^key[1] == key[2]
        ans &= key[1]^key[2] == key[0]
        ans &= key[2]^key[0] == key[1]
        ans &= len(set(value)) == 1
    print("Yes" if ans else "No")
main()

Solution (Python):
from collections import Counter

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

c = Counter(a)
s = list(set(a))
l = len(s)

if l == 1 and a[0] == 0:
    print('Yes')
    exit()
if len(a) % 3 == 0:
    if l == 2 and c[0] == n // 3:
        print('Yes')
        exit()
    if l == 3 and s[0] ^ s[1] ^ s[2] == 0:
        tmp = n//3
        if all(x == tmp for x in c.values()):
            print('Yes')
            exit()

print('No')

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
S = set(A)
if len(S) > 3:
    print("No")
elif len(S) == 1:
    if A[0] == 0:
        print("Yes")
    else:
        print("No")
elif len(S) == 2:
    if A.count(0) == N // 3 and N % 3 == 0:
        print("Yes")
    else:
        print("No")
else:
    L = list(S)
    y = L[0] ^ L[1] ^ L[2]
    if all(A.count(x) == N // 3 for x in S) and N % 3 == y == 0:
        print("Yes")
    else:
        print("No")

Solution (Python):

import collections


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

    c = collections.Counter(a).most_common()
    ans = "No"
    if len(c) == 3 and c[0][1] == c[1][1] == c[2][1]:
        if c[0][0] ^ c[1][0] ^ c[2][0] == 0:
            ans = "Yes"
    elif len(c) == 2 and c[0][1] == 2 * c[1][1]:
        if c[0][0] ^ c[0][0] ^ c[1][0] == 0:
            ans = "Yes"
    elif len(c) == 1 and c[0][0] == 0:
        ans = "Yes"
    print(ans)


if __name__ == "__main__":
    main()

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

l=sorted(list(map(int,input().split())))
zero=l.count(0)
if zero==N:
   print("Yes")
   exit()
elif len(set(l)) == 2:
   s=l.count(l[-1])
   if zero==N//3 and s==N*2//3:
      print("Yes")
      exit()
elif len(set(l))==3:
   a,b,c=list(set(l))
   if a^b^c==0 and l.count(a)== l.count(b)==l.count(c):
      print("Yes")
      exit()
print("No")

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    if i not in d:
        d[i] = 1
    else:
        d[i] +=1
if len(d) == 1 and 0 in d:
    print('Yes')
elif len(d) == 2:
    for i in d:
        if i == 0 and d[i] * 3 != N or i != 0 and d[i] * 3 != 2 * N:
            print('No')
            exit()
    print('Yes')
elif len(d) == 3:
    s = 0
    for i in d:
        s ^= i
        if d[i] * 3 != N:
            print('No')
            exit()
    if s != 0:
        print('No')
    else:
        print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    if i not in d:
        d[i] = 1
    else:
        d[i] +=1
if len(d) == 1 and list(d.keys())==[0]:
    print('Yes')
elif len(d) == 2:
    for i in d:
        if i == 0 and d[i] * 3 != N or i != 0 and d[i] * 3 != 2 * N:
            print('No')
            exit()
    print('Yes')
elif len(d) == 3:
    s = 0
    for i in d:
        s ^= i
        if d[i] * 3 != N:
            print('No')
            exit()
    if s != 0:
        print('No')
    else:
        print('Yes')
else:
    print('No')

Solution (Python):
def main():
    N = int(input())
    a = list(map(int,input().split()))
    a_set = set(a)
    if len(a_set) > 3:
        return('No')

    if len(a_set) == 1:
        if sum(a_set) == 0:
            return('Yes')
        else:
            return('No')

    elif len(a_set) == 2:
        a_1,a_2 = sorted(a_set)
        if a_1 == 0 and a.count(a_1)*3 == N:
            return ('Yes')
        else:
            return('No')

    else:
        a_1,a_2,a_3 = a_set
        if a.count(a_1) == a.count(a_2) and a.count(a_1) == a.count(a_3) and a.count(a_3) == a.count(a_2):
            if a_1^a_2 == a_3:
                return ('Yes')
            else:
                return('No')
        else:
            return('No')

print(main())

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

Solution (Python):
from collections import Counter

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

cnt=sorted(list(Counter(a).items()),key=lambda x:x[0])

if len(cnt)==1 and cnt[0][0]==0:
    print('Yes')
elif n%3==0 and len(cnt)==2 and cnt[0][0]==0 and cnt[0][1]==n//3:
    print('Yes')
elif n%3==0 and len(cnt)==3 and cnt[0][0]^cnt[1][0]^cnt[2][0]==0 and cnt[0][1]==n//3 and cnt[1][1]==n//3 and cnt[2][1]==n//3:
    print('Yes')
else:
    print('No')

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
if sum(A) ==0: 
  print("Yes")
  exit()

if N%3 != 0:
  print("No")
else:
  dic = {}
  for x in A:
    if x in dic:
      dic[x] += 1
    else:
      dic[x] = 1
  V = list(dic.values())
  if len(V) == 2:
    K = list(dic.keys())
    if K[0] == 0 and dic[K[1]] == dic[0]*2:
      print("Yes")
    elif K[1] == 0 and dic[K[0]] == dic[0]*2:
      print("Yes")
    else:
      print("No")
    exit()  
  if len(V) != 3:
    print("No")
    exit()
  if V[0] == V[1] and V[1] == V[2]:
    K = list(dic.keys())
    if K[0]^K[1] == K[2] and K[1]^K[2] == K[0] and K[2]^K[0] == K[1]:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

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

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

if len(SA) == 2 and 0 in SA and CA[0] * 3 == N:
    print("Yes")
    exit()

for v in CA.values():
    if 3 * v != N:
        break
else:
    a, b, c = CA.keys()
    if a ^ b ^ c == 0:
        print("Yes")
        exit()

print("No")

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  

N = I()
a = LI()



if N % 3 != 0:
    for i in range(N):
        if a[i] != 0:
            print('No')
            break
    else:
        print('Yes')
    exit()

B = list(set(a))
b = len(B)
n = N//3
if b > 3:
    print('No')
elif b == 1:
    for i in range(N):
        if a[i] != 0:
            print('No')
            break
    else:
        print('Yes')
elif b == 2:
    x,y = B
    c = a.count(x)
    if x != 0 and y != 0:
        print('No')
    elif x == 0:
        if c == n:
            print('Yes')
        else:
            print('No')
    else:
        if c == 2*n:
            print('Yes')
        else:
            print('No')
else:
    x,y,z = B
    c = a.count(x)
    d = a.count(y)
    if not (c == d == n):
        print('No')
    else:
        if x ^ y == z:
            print('Yes')
        else:
            print('No')

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def err():
    print('No')
    quit()
def ok():
    print('Yes')
    quit()

n = inp()
a = inpl()
a.sort()
c = Counter(a)
now = a[0]
for i in range(1,n):
    now ^= a[i]
if now: err()
if a[0] == a[-1] == 0: ok()
if n == 3:
    x,y,z = a
    if x == 0 and y == z: ok()
if n%3: err()
if len(c.keys()) == 3:
    for x in c.values():
        if x != n//3:
            err()
    x,y,z = c.keys()
    if x^y != z:
        err()
elif len(c.keys()) == 2:
    x,y = sorted(list(c.values()))
    if x != n//3 or y != n//3*2:
        err()
    x,y = sorted(list(c.keys()))
    if x != 0: err()
else: err()
ok()

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

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

c = Counter(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(set(a)) == 1 and a[0] == 0:
    print('Yes')
elif N % 3 == 0:
    l = [*Counter(a).values()]
    res = 0
    for s in set(a):
        res ^= s
    if len(l) == 3 and res == 0 and len(set(l)) == 1:
        print('Yes')
    elif len(l) == 2 and a.count(0) == N//3:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Solution (Python):
n = int(input())
al = list(map(int, input().split()))
al.sort()
al_cnt_d = {}

if al[0] == 0 and al[n-1] == 0:
    print('Yes')

elif n == 3:
    if al[0] ^ al[1] ^al[2] == 0:
        print('Yes')
    else:
        print('No')

elif n%3 == 0:
    for a in al:
        al_cnt_d.setdefault(a,0)
        al_cnt_d[a] += 1

    if len(al_cnt_d) == 3:
        val = 0
        for k,v in al_cnt_d.items():
            val = val^k
            if v != n//3:
                print('No')
                exit()
        if val == 0: print('Yes')
        else: print('No')
    elif len(al_cnt_d) == 2:
        if 0 not in al_cnt_d or al_cnt_d[0] != n//3:
            print('No')
            exit()            
        else:
            print('Yes')
    else:
        print('No')


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):
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    flg = False
    if len(set(A)) == 1 and 0 in set(A):
        flg = True
    else:
        if n % 3 == 0:
            D = Counter(A)
            if len(D) == 3:
                t = 0
                V = set()
                for k, v in D.items():
                    t ^= k
                    V.add(v)
                if len(V) == 1 and t == 0:
                    flg = True
            elif len(D) == 2 and D.get(0, -1) != -1:
                v = D[0]
                if n - v == n * 2 // 3:
                    flg = True
    print("Yes" if flg else "No")


if __name__ == '__main__':
    resolve()

Solution (Python):
from collections import Counter
import sys

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


if all([x == 0 for x in arr]):
    print("Yes")
    sys.exit()


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

c = Counter(arr)


if len(c) == 2:
    if c[0] == n // 3:
        print("Yes")
        sys.exit()
    else:
        print("No")
        sys.exit()


elif len(c) == 3:
    result = list(c.values())
    if result[0] == result[1] == result[2]:
        ans1 = True
    else:
        ans1 = False
else:
    print("No")
    sys.exit()

result = list(c.keys())
ans2 = result[0] == result[1] ^ result[2] and result[1] == result[0] ^ result[2] and result[2] == result[0] ^ result[1]

print("Yes" if ans1 and ans2 else "No")

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  

N = I()
a = LI()

if N % 3 != 0:
    for i in range(N):
        if a[i] != 0:
            print('No')
            break
    else:
        print('Yes')
    exit()

B = list(set(a))
b = len(B)
n = N//3
if b > 3:
    print('No')
elif b == 1:
    for i in range(N):
        if a[i] != 0:
            print('No')
            break
    else:
        print('Yes')
elif b == 2:
    x,y = B
    c = a.count(x)
    d = a.count(y)
    if x != 0 and y != 0:
        print('No')
    elif x == 0:
        if c == n:
            print('Yes')
        else:
            print('No')
    else:
        if d == n:
            print('Yes')
        else:
            print('No')
else:
    x,y,z = B
    c = a.count(x)
    d = a.count(y)
    if not (c == d == n):
        print('No')
    else:
        if x ^ y == z:
            print('Yes')
        else:
            print('No')

Solution (Python):
from collections import Counter

n = int(input())

A = [int(i) for i in input().split()]
counts = Counter(A)
tmp = 0



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



if len(counts.items()) == 3 and n % 3 == 0:
    tmp = 0
    for x, k in counts.items():
        if k == n // 3:
            tmp ^= x
        else:
            print("No")
            quit()
    if tmp == 0:
        print("Yes")
        quit()
    else:
        print("No")
        quit()



if len(counts.items()) == 2 and n % 3 == 0:
    if counts.most_common()[1][0] == 0 and counts.most_common()[1][1] == n // 3:
        print("Yes")
        quit()
    else:
        print("No")
        quit()

print("No")

Solution (Python):
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
l = Counter(a)
all_xor = 0
if N % 3 != 0:
    if l[0] != N:
        print("No")
        exit()
    else:
        print("Yes")
        exit()
for _l in l.keys():
    if l[_l] == N // 3:
        continue
    if _l == 0:
        if l[0] == N:
            print("Yes")
            exit()
        if l[0] != N // 3 or len(l) != 2:
            print("No")
            exit()
    if l[_l] == (2 * N) // 3 and l[0] == N // 3:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
for i in range(N):
    all_xor = a[i] ^ all_xor
if all_xor == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
from collections import*
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in a[1:]:
  ans^=i
a=dict(Counter(a))
ak=list(a.keys())
if len(a)==1 and ak[0]!=0:ans=1
elif len(a)==2 and a.get(0)!=n//3:ans=1
elif len(a)==3 and not(a[ak[0]]==a[ak[1]]==a[ak[2]]==n//3):ans=1
elif len(a)>3:ans=1
print(['Yes','No'][ans>0])

Solution (Python):
from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
tmp1 = list(A.items())
tmp1.sort()
if len(tmp1) == 1 and tmp1[0][0] == 0 or len(tmp1) == 2 and tmp1[0][0] == 0 and tmp1[1][1] == N // 3 * 2 and tmp1[0][1] == N // 3 or len(tmp1) == 3 and (tmp1[0][0] ^ tmp1[1][0] ^ tmp1[2][0]) == 0 and tmp1[0][1] == tmp1[1][1] == tmp1[2][1] == N // 3:
    print('Yes')
else:
    print('No')

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

if lis.count(0) == n:
    print('Yes')
elif n % 3 != 0:
    print('No')
elif len(set(lis)) == 2:
    if 0 in set(lis):
        if lis.count(0) == n/3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(set(lis)) == 3:
    xor = 0
    for  a in set(lis):
        if lis.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())
d = Counter(list(map(int, input().split())))
if len(d) == 1:
    if d[0] == n:
        print("Yes")
        exit()
elif len(d) == 2:
    if n%3 == 0 and d[0] == n//3:
        print("Yes")
        exit()
elif len(d) == 3:
    k = list(d.keys())
    if n%3 == 0 and k[0] ^ k[1] ^ k[2] == 0 and d[k[0]] == d[k[1]] == d[k[2]]:
        print("Yes")
        exit()
print("No")