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 sys

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

for a in A:
  if a in dict.keys():
    dict[a] = dict[a] + 1
  else:
    dict[a] = 1

if len(list(dict.keys())) > 3:
  print('No')
  sys.exit()
elif len(list(dict.keys()))==1:
  keys=list(dict.keys())
  if keys[0]==0:
    print('Yes')
    sys.exit()
  else:
    print('No')
    sys.exit()
elif len(list(dict.keys()))==2:
  keys=list(dict.keys())
  a0=keys[0]
  a1=keys[1]
  a2=''
  b0=bin(a0)[2:]
  b1=bin(a1)[2:]
  if len(b0)<len(b1):
    b0,b1=b1,b0
  b1=b1.zfill(len(b0))
  for s0,s1 in zip(b0,b1):
    a2 = a2 + str( int(s0)^int(s1) )
  a2=int(a2,2)
  
  if a2==a0 or a2==a1:
    vals=list(dict.values())
    if vals[0]/2==vals[1] or vals[0]==vals[1]/2:
      print('Yes')
      sys.exit()
    else:
      print('No')
      sys.exit()
  
keys=list(dict.keys())
vals=set(dict.values())

if len(vals)> 1:
  print('No')
  sys.exit()
  
a0=keys[0]
a1=keys[1]
a2=''
b0=bin(a0)[2:]
b1=bin(a1)[2:]
if len(b0)<len(b1):
  b0,b1=b1,b0
b1=b1.zfill(len(b0))
for s0,s1 in zip(b0,b1):
  a2 = a2 + str( int(s0)^int(s1) )
a2=int(a2,2)

if a2!=keys[2]:
  print('No')
  sys.exit()

print('Yes')

Solution (Python):
def main():
    N = int(input())
    array = list(map(int, input().split()))
    set_array = list(set(array))
    if N != len(array):
        return "No"
    if N < 3:
        return "No"
    if len(set_array) == 1 and set_array[0] == 0:
        return "Yes"
    if len(set_array) == 3:
        for i in range(2):
            if array.count(set_array[i]) != array.count(set_array[i+1]):
                return "No"
        x = set_array[0]
        y = set_array[1]
        z = set_array[2]
        if x ^ y == z and y ^ z == x and x ^ z == y:
            return "Yes" 
    if len(set_array) == 2:
        x = min(set_array)
        y = max(set_array)
        if array.count(x)*2 == array.count(y):
            if x == 0 and y^y == 0 and 0^y == y:
                return "Yes"
    return "No"

print(main())

Solution (Python):
n = int(input())
line = list(map(int,input().split( )))
s = list(set(line))

if n%3==0 and 0 in line and line.count(0)==n//3 and len(s)<=2:
    print('Yes')
elif  n%3==0 and len(s)==3 and s[0]^s[1]==s[2] and s[1]^s[2]==s[0] and line.count(s[0])==n//3 and line.count(s[1])==n//3:
    print('Yes')
elif s == [0]:
    print('Yes')
else:
    print('No')

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

if 0 in a:
    set_a = list(set(a))
    set_a = sorted(set_a)
    if len(set_a) == 1:
        print("Yes")
    elif len(set_a) == 2:
        if 2*a.count(set_a[0]) == a.count(set_a[1]):
            print("Yes")
        else:
            print("No")
    else:
        print("No")

else:
    if n%3 != 0:
        print("No")

    else:
        if len(set(a)) != 3 or a.count(list(set(a))[0]) != int(n/3) or a.count(list(set(a))[1]) != int(n/3) or a.count(list(set(a))[2]) != int(n/3):
            print("No")

        else:
            set_a = list(set(a))
            if set_a[0] == set_a[1]^set_a[2] and set_a[1] == set_a[2]^set_a[0] and set_a[2] == set_a[1]^set_a[0]:
                print("Yes")
            else:
                print("No")

Solution (Python):
import collections
n=input()
a=list(map(int,input().split()))
b=set(a)
c=list(b)
c.sort()
cnt=collections.Counter(a)
if len(b)==1:
  if c[0]==0:
    print('Yes')
  else:
    print('No')
if len(b)==2:
  if c[0]==0 and cnt[c[1]]%2==0 and cnt[c[0]]*2>=cnt[c[1]]:
    print('Yes')
  else:
    print('No')
if len(b)==3:
  if c[0]==0:
    print('No')
  elif cnt[c[0]]==cnt[c[1]]==cnt[c[2]] and c[0]^c[1]==c[2]:
        print('Yes')
  else:
      print('No')
if len(b)>3:
  print('No')

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


ans = 0
if n == 3:
    if a[0]^a[1] == a[2]:
        ans = 1
    else:
        ans = 0
elif n == 4:
    if a[0]==0 and a[1]==0 and a[2]==0 and a[3]==0:
        ans = 1
    else:
        ans = 0
else:
    tmp = []
    cnt = []
    for i in range(n):
        if i == 0:
            tmp.append(a[i])
            cnt.append(1)
        else:
            if a[i-1] == a[i]:
                cnt[-1] += 1
            else:
                tmp.append(a[i])
                cnt.append(1)
    if n % 3 != 0:
        if tmp[0] == 0 and cnt[0] == n:
            ans = 1
    else:
        if len(tmp) == 3:
            if cnt[0] == cnt[1] and cnt[1] == cnt[2] and tmp[0]^tmp[1] == tmp[2]:
                ans = 1
        if len(tmp) == 2:
            if tmp[0] == 0:
                if cnt[0]*2 == cnt[1]:
                    ans = 1
        if len(tmp) == 1:
            if tmp[0] == 0:
                ans = 1
if ans == 1:
    print("Yes")
else:
    print("No")

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

if n % 3 == 0:
    a.sort()
    m = n // 3
    if a[0] == a[m - 1] and a[m] == a[2 * m - 1] and a[2 * m] == a[3 * m - 1]:
        if a[0] ^ a[m] ^ a[2 * m] == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    if max(a) == min(a):
        print('Yes')
    else:
        print('No')

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)


def solve():
    N = int(input())
    a_list = list(map(int, input().split()))
    a_list.sort()

    import collections
    c = collections.Counter(a_list)
    keys = sorted(c.keys())
    nk = len(keys)

    dprint(c)
    dprint(keys)

    
    found = False
    start = keys[0]
    ccand = []
    rcand = []
    for i in range(0, nk):

        
        if i == 0 and c[keys[i]] <= 1:
            continue

        center = keys[i]
        max = start + center

        for j in range(i, nk):
            right = keys[j]

            
            if i == j and i == 0 and c[keys[i]] <= 2:
                continue
            if i == j and c[keys[i]] <= 1:
                continue

            if right > max:
                
                break

            if right == start ^ center:
                found = True
                ccand.append(center)
                rcand.append(right)
                
        
        
        

    if found == False:
        dprint("first pair search failed")
        print("No")
        return

    dprint("first set created")
    dprint(ccand, rcand)
    center = ccand[-1]
    right = rcand[-1]

    c[start] = c[start] - 1
    c[center] = c[center] - 1
    c[right] = c[right] - 1

    
    left = center
    center = right
    dprint(start, left, center)

    cnt = 3
    while True:
        
        if cnt == N:
            break

        
        right = left ^ center

        
        rcount = c.get(right, -1)
        if rcount <= 0:
            dprint("break rcount:", rcount)
            print("No")
            return

        dprint("found", right, rcount)

        
        c[right] = c[right] - 1
        left = center
        center = right

        cnt += 1
        dprint("next", cnt, left, center)

    if start ^ left == center:
        print("Yes")
    else:
        dprint("last check failed", start, left, center)
        print("No")


solve()

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

N = int(input())
b = list(map(int, input().split()))
checker = Counter(b)
a = []
for key in checker.keys():
    a.append(key)
if len(a) == 1 and a[0] == 0:
    print('Yes')
    exit()
if len(a) == 2:
    if a[0] == 0:
        if checker[0] == int(N/3) and checker[a[1]] == int(2*N/3):
            print('Yes')
            exit()
    elif a[0] != 0:
        if checker[0] == int(N/3) and checker[a[0]] == int(2*N/3):
            print('Yes')
            exit()
if len(a) != 3:
    print('No')
    exit()
if a[0] == a[1]^a[2] and a[1] == a[0]^a[2] and a[2] == a[0]^a[1]:
    ans = 1
else:
    ans = 0
for key, value in checker.items():
    if N % 3 == 0 and value == int(N/3):
        ans *= 1
    else:
        ans *= 0
if ans == 1:
    print('Yes')
elif ans == 0:
    print('No')

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

ans = 'No'
hat1 = max(a)
hat2 = min(a)
if hat1 == 0 and a.count(hat1) == N:
    ans = 'Yes'
if N%3 == 0:
    if hat2 == 0 and a.count(hat1) == int(2*N/3) and a.count(hat2) == int(N/3):
        ans = 'Yes'
    if a.count(hat1) == int(N/3) and a.count(hat2) == int(N/3) and a.count(hat1^hat2) == int(N/3):
        ans = 'Yes'
print(ans)

Solution (Python):

def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = a[0]
    for i in range(1, N, 1):
        b = b ^ a[i]
    if b == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

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

eachbit=[0]*32
for i in range(N):
    bin_str = format(A[i],'032b')

    for j in range(1,33):
        if bin_str[-j] == '1':
            eachbit[j-1] += 1


even = True
for e in eachbit:
    if e % 2 != 0:
        even = False

if even:
    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 permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    a=LIST()
    a_=a.copy()

    r=0
    for x in a:
        r ^= x 

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

if  __name__=='__main__':
    main()

Solution (Python):
import sys
import itertools
n=int(input())
l=list(map(int,input().split()))
l.sort()
s=set(l)
if len(s)>=4 :print("No");sys.exit()
if len(s)==1:print("Yes" if 0 in s else "No");sys.exit()
s=list(s);s.sort()
if len(s)==2:
  if 0 not in s:print("No");sys.exit()
  if n%3==1:
    if l.count(0)==(n-1)//3:print("Yes");sys.exit()
    else:print("No");sys.exit()
  elif n%3==2:
    if l.count(0)==(n+1)//3:print("Yes");sys.exit()
    else:print("No");sys.exit()
  elif n%3==0:
    if l.count(0)==n//3:print("Yes");sys.exit()
    else:print("No");sys.exit()
a=l.count(s[0]);b=l.count(s[1]);c=l.count(s[2])
if a!=b or b!=c or c!=a:print("No");sys.exit()
flag=0
for i in itertools.permutations(s):
  if i[0]^i[2]==i[1] and i[1]^i[2]==i[0] and i[0]^i[1]==i[2]:flag+=1
if flag!=0:print("Yes")
else:print("No")

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

N = int(input())

c = Counter((int(x) for x in input().split()))






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

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

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

Solution (Python):

def solve():
    N = int(input())
    A = dict()
    for a in map(int, input().split()):
        A[a] = A.get(a,0) + 1
    if N % 3:
        if 0 in A and A[0] == N:
            return 'Yes'
        else:
            return 'No'
    else:
        if 0 in A and A[0] == N:
            return 'Yes'
        elif 0 in A and A[0] == N//3:
            if len(A) == 2:
                return 'Yes'
            else:
                return 'No'
        elif len(A) == 3:
            if len(set(A.values())) == 1:
                a,b,c = A.keys()
                if c == a^b:
                    return 'Yes'
                else:
                    return 'No'
            else:
                return 'No'
        else:
            return 'No'

if __name__ == '__main__':
    print(solve())

Solution (Python):
import collections
N = int(input())
W = list(map(int, input().split()))
c = dict(collections.Counter(W))

if len(c.keys()) == 1:
  if c.get(0, False) == False:
    print('No')
  else:
    print('Yes')
if len(c.keys()) == 2:
  num = list(c.values())
  num = sorted(num)
  if 0 in c:
    if c[0]*2 == num[1]:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
if len(c.keys()) == 3:
  num = list(c.values())
  key = list(c.keys())
  if num[0] == num[1]:
    if num[0] == num[2]:
      if bin(key[0]^key[1]) == bin(key[2]):
        print("Yes")
      else:
        print("No")
    else:
      print("No")
  else:
    print("No")
if len(c.keys()) >= 4:
  print("No")

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

Solution (Python):
def resolve():
    N = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    a_xor = a[0] ^ a[1]
    for i in range(2, N):
        a_xor = a_xor ^ a[i]
    if (a_xor == 0):
        print("Yes")
    else:
        print("No")
resolve()

Solution (Python):
N = int(input())
data = {}
bits = 0
bit_table = [set() for _ in range(31)]
for a in map(int, input().split()):
	bits |= a
	if a in data:
		data[a] += 1
	else:
		data[a] = 1
	i = 0
	b = a
	while b:
		if b % 2 == 1:
			bit_table[i].add(a)
		b //= 2
		i += 1

def pop(data, a):
	if a in data:
		if data[a] == 1:
			del data[a]
		else:
			data[a] -= 1
		return a
	else:
		return None

def check2(data0, a1, a2):
	if (a1 | a2) != bits:
		return False
	
	data = { k: data0[k] for k in data0 }
	a0 = a1
	pop(data, a1)
	pop(data, a2)
	
	while data:
		a3 = a1 ^ a2
		a4 = pop(data, a3)
		if a4 == None:
			return False
		a1 = a2
		a2 = a3
	return a0 == (a1 ^ a2)

def check(data):
	keys = list(data.keys())
	a1 = keys[0]
	b = bits & (~a1)
	cands = set(keys)
	i = 0
	while b:
		if b % 2 == 1:
			cands &= bit_table[i]
		b //= 2
		i += 1
	
	for a2 in cands:
		if a1 != a2 or data[a1] > 1:
			if check2(data, a1, a2):
				return True
	return False

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

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

readline = sys.stdin.readline

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


x = A[0]
y, z = x, x
for a in A:
    if a != x:
        y = a
        break
for a in A:
    if a != x and a != y:
        z = a
        break

if N % 3 == 0:
    cx, cy, cz = A.count(x), A.count(y), A.count(z)
    if x != y and x != z:
        if cx + cy + cz == N:
            if cx == cy and cx == cz and ((x ^ z == y) or (x ^ y == z)):
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    elif x != y:
        x, y = max(x,y), min(x,y)
        cx, cy = A.count(x), A.count(y)
        if cy * 2 == cx and y == 0:
            print('Yes')
        else:
            print('No')
    elif x == y:
        if x == 0:
            print('Yes')
        else:
            print('No')
else:
    if x == y:
        if x == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Solution (Python):
def xor(n1, n2):
  if n2=="0":
    return n1
  elif n2=="1":
    if n1=="1":
      return "0"
    else:
      return "1"
      
def bitxor(n1, n2):
 
  bn1 = bin(n1)[2:]
  bn2 = bin(n2)[2:]
  if n1<n2:
    bn1 = bn1.zfill(len(bn2))
  else:
    bn2 = bn2.zfill(len(bn1))
    
  n3 = [xor(b1,b2) for b1,b2 in zip(bn1, bn2)]
  n3 = "".join(n3)
  return int(n3, 2)
 
 
n = int(input())
a = [int(x) for x in input().split()]
a_unique = list(set(a))
la = len(a)
lau = len(a_unique)

if a_unique==[0]:
  print("Yes")

elif la%3==0 and (0 in a_unique):
  u0 = a.count(0)
  if u0*3!=la:
    print("No")
  else:
    a_unique.remove(0)
    tmp = [(a.count(ai)%2==0) for ai in a_unique]
    if len(tmp)==sum(tmp):
      print("Yes")
    else:
      print("No")

elif la%3==0 and lau==2 and (0 in a_unique):
  u0 = a.count(0)
  if a_unique[0]==0:
    num = a_unique[1]
  else:
    num = a_unique[0]
  u1 = a.count(num)
  if u0*2==u1:
    print("Yes")
elif la%3!=0 or lau!=3:
  print("No")
else:
  u0 = a.count(a_unique[0])
  u1 = a.count(a_unique[1])
  u2 = a.count(a_unique[2])
 
  if (a_unique[2]== bitxor(a_unique[0], a_unique[1])) and (u0==u1 and u1==u2):
    print("Yes")
  else:
    print("No")

Solution (Python):
import sys
from collections import deque, defaultdict
import copy
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

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


numnum=defaultdict(int)
for i in range(N):
    numnum[a[i]]+=1

if len(numnum) > 3:
    print("No")
    exit()


if len(numnum) == 1:
    for num in numnum:
        if num == 0:
            print("Yes")
        else:
            print("No")
        exit()


for num in numnum:
    if numnum[num] % (N//3) != 0:
        print("No")
        exit()

num3=[]
for num in numnum:
    num3.append(num)

if len(num3) == 2:

    if 0 in num3 and numnum[0] == N//3:
        print("Yes")
        exit()
    else:
        print("No")
        exit()


if num3[0]^num3[1] == num3[2]:
    print("Yes")
    exit()
else:
    print("No")
    exit()

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]
ite = 0
for i in range(N):
    if a[i] != 0:
        break
    else:
        ite += 1
if ite == N :
    print("Yes")
    exit()

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

a = sorted(a)
for j in range(n-1):
    if a[j] != a[j + 1]:
        print("No")
        exit()


for k in range(n, 2*n-1):
    if a[k] != a[k + 1]:
        print("No")
        exit()

for p in range(2*n, 3*n-1):
    if a[p] != a[p + 1]:
        print("No")
        exit()


if a[n] ^ a[0] != a[2*n]:
    print("No")
    exit()

print("Yes")

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

if len(count) > 3:
    print("No")
    exit(0)
if N%3 == 0 and len(count) == 3:
    a, b, c = list(count.keys())
    la, lb, lc = list(count.values())
    if a ^ b == c and b ^ c == a and c ^ a == b and la == lb and lb == lc:
        print("Yes")
    else:
        print("No")
elif N%3 == 0 and len(count) == 2:
    a, b = list(count.keys())
    la, lb = list(count.values())
    if (a == 0 and la*2 == lb) or (b == 0 and lb*2 == la):
        print("Yes")
    else:
        print("No")
elif len(count)==1 and list(count.keys())[0] == 0:
    print("Yes")
else:
    print("No")

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

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

a_set=list(set(a))
a_set.sort()



if len(a_set)==1 and a_set[0]==0:
    print("Yes")
    sys.exit(0)


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


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

Solution (Python):
import sys

N = int(input())
a = list(map(int, input().split()))
 
x = 0
y = 0
z = 0

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

if N % 3 != 0:
  print('No')
 
elif a.count(0) != 0:
  if a.count(0) != N / 3:
    print('No')
    sys.exit()
    
  else:
    for i in range(N):
      if a[i] != 0 and a[i] != x:
        if x == 0:
          x = a[i]
          continue
        else:
          print('No')
          sys.exit()
        
    print('Yes')
    

else:
  for i in range(N):
    if a[i] != x and a[i] != y and a[i] != z:
      if x == 0:
        x = a[i]
        continue
      elif y == 0:
        y = a[i]
        continue
      elif z == 0:
        z = a[i]
        continue
      else:
        print('No')
        sys.exit()
  
  if x ^ y == z and a.count(x) == a.count(y) and a.count(y) == a.count(z):
    print('Yes')
  else:
    print('No')

Solution (Python):
def calc(N, A):
    _exist = False
    counter = {}
    for a in A:
        counter[a] = 1 + (counter[a] if a in counter else 0)
    if (N % 3 == 0 and len(counter) == 3):
        keys = list(counter.keys())
        values = list(counter.values())
        d = max(values) - min(values)
        _exist = d == 0 and keys[0] ^ keys[1] == keys[2]
    elif (N % 3 == 0 and len(counter) == 2):
        keys = list(counter.keys())
        values = list(counter.values())
        d = max(values) - min(values)
        _exist = d == N // 3 and (keys[0] == 0 or keys[1] == 0)
    else:
        _exist = 0 in counter and counter[0] == N
    print('Yes' if _exist else 'No')


N = int(input())
A = [int(s) for s in input().split(' ')]
calc(N, A)

Solution (Python):
n = input()
dic = {}
for i in map(int, raw_input().split()):
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
if len(dic) > 3:
	print "No"
elif len(dic) == 3:
	vals = []
	for i in dic:
		vals.append(i)
	if vals[0]^vals[2] != vals[1] or vals[1]^vals[0] != vals[2] or vals[0] != vals[1]^vals[2]:
		print "No"
	elif max(dic.values()) - min(dic.values()) > 1:
		print "No"
	else:
		print "Yes"
elif len(dic) == 2:
	if 0 in dic and dic[0] == n/3 and n%3 == 0:
		print "Yes"
	else:
		print "No"
else:
	if 0 in dic.keys():
		print "Yes"
	else:
		print "No"

Solution (Python):

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

ans = True
if N % 3 != 0:
    for i in range(N):
        if a[i] != 0:   
            ans = False
else:
    first = a[0]
    i_second = -1
    for i in range(1, N):
        if a[i] != first:
            second = a[i]
            i_second = i
            break
        
    if i_second == -1:
        for i in range(N):
            if a[i] != 0:
                ans = False
    else:
        i_third = -1
        for i in range(i_second+1, N):
            if (a[i] != first) and (a[i] != second):
                third = a[i]
                i_third = i
                break
        if i_third == -1:
            ans = False
            cnt_first = 0
            cnt_second = 0
            for i in range(N):
                if a[i] == first:
                    cnt_first += 1
                elif a[i] == second:
                    cnt_second += 1
            if first ^ second == second:
                if (cnt_first == N/3) and (cnt_second == N*2/3):
                    ans = True
            if first ^ second == first:
                if (cnt_first == N*2/3) and (cnt_second == N/3):
                    ans = True
        else:
            if (first ^ second != third) or (second ^ third != first) or (third ^ first != second):
                ans = False
            else:
                cnt_first = 0
                cnt_second = 0
                cnt_third = 0
                for i in range(N):
                    if a[i] == first:
                        cnt_first += 1
                    elif a[i] == second:
                        cnt_second += 1
                    elif a[i] == third:
                        cnt_third += 1
                if (cnt_first != N/3) or (cnt_second != N/3) or (cnt_third != N/3):
                    ans = False

if ans is True:
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())
a = [int(i) for i in input().split(' ')]
numbers = []
numbers.append(a[0])
for i in a:
    if i != numbers[0] and len(numbers) == 1:
        numbers.append(i)
    if i != numbers[0] and i != numbers[1]:
        numbers.append(i)
        break

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

if len(numbers) == 3:
    if a.count(numbers[0]) != a.count(numbers[1]):
        print('No')
        exit(0)
    if a.count(numbers[0]) != a.count(numbers[2]):
        print('No')
        exit(0)
    if len(a) != a.count(numbers[0])+a.count(numbers[1])+a.count(numbers[2]):
        print('No')
        exit(0)

    if numbers[0]^numbers[1] == numbers[2]:
        print('Yes')
        exit(0)
    elif numbers[0]^numbers[2] == numbers[1]:
        print('Yes')
        exit(0)
    elif numbers[1]^numbers[2] == numbers[0]:
        print('Yes')
        exit(0)
    else:
        print('No')
else:
    if len(a) != a.count(numbers[0])+a.count(numbers[1]):
        print('No')
        exit(0)
    if numbers[0] == 0 or numbers[1] == 0:
        if numbers[0] == 0:
            if a.count(numbers[1]) != 2*a.count(numbers[0]):
                print('No')
                exit(0)
        elif a.count(numbers[0]) != 2*a.count(numbers[1]):
            print('No')
            exit(0)
        print('Yes')
        exit(0)
    else:
        print('No')
        exit(0)

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

b_list = []
for h in hat_list:
    
    b_list.append(format(h,'b').zfill(30))

for n in range(30):
    test_list = []
    for b in b_list:
        test_list.append(b[n])
    if test_list.count('1') > 0:
        if test_list.count('1') != test_list.count('0') * 2:
            print("No")
            break
else:
    print("Yes")

Solution (Python):
from sys import exit
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A = list(map(int, input().split()))

def noexit():
    print('No')
    exit()

def yesexit():
    print('Yes')
    exit()

setA = set(A)
if 0 in setA:
    if len(setA) == 1: yesexit()
    elif len(setA) == 2 and N%3 == 0:
        A.sort()
        listA = list(setA)
        listA.remove(0)
        neww_list = [0] * (N//3) + [listA[0]] * ((N//3)*2)
        neww_list.sort()
        if A == neww_list:
            yesexit()
        else:
            noexit()
    else: noexit()

if N%3 != 0: noexit()
if len(setA) != 3: noexit()

listA = list(setA)
if listA[0]^listA[1] == listA[2]:
    new_list = [listA[0]]*(N//3) + [listA[1]]*(N//3) + [listA[2]]*(N//3)
    A.sort()
    new_list.sort()
    if A == new_list:
        yesexit()
    else:
        noexit()
else: noexit()

Solution (Python):
def main():
    n = int(input())
    *alist, = map(int, input().split())

    aset = list(set(alist))
    if len(aset) == 1 and aset[0] == 0:
        print('Yes')
        return

    if len(aset) == 2:
        a, b = aset
        acnt = {a: 0, b: 0}
        for aa in alist:
            acnt[aa] += 1

        if a ^ b == a:
            if acnt[a] == acnt[b] * 2:
                print('Yes')
                return
        if b ^ a == b:
            if acnt[a] * 2 == acnt[b]:
                print('Yes')
                return
        print('No')
        return

    if len(aset) != 3:
        print('No')
        return
    else:
        a, b, c = aset
        if a ^ b != c:
            print('No')
            return

        acnt = {a: 0, b: 0, c: 0}
        for aa in alist:
            acnt[aa] += 1

        if acnt[a] != acnt[b] or acnt[b] != acnt[c]:
            print('No')
            return

        print('Yes')
        return


main()

Solution (Python):
import sys, math
 
N = int(input())
A = [int(i) for i in input().split()]

result = 0
for i in range(N):
  result = result ^ A[i]
  

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

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int ,input().split()))
C = Counter(A)
MAXD = 30
B = [('0' * MAXD + bin(a)[2:])[-30:] for a in A]

ps = []
res = True
for i in range(MAXD):
    bs = list(b[i] for b in B)
    c = Counter(bs)
    if c['0'] == N:
        continue
    if c['0'] == N // 3:
        if N % 3 == 0:
            if len(ps) != 0:
                if all(p == b for (b, p) in zip(bs, ps)):
                    continue
                bc = Counter(int(p + b, 2) for (b, p) in zip(bs, ps))
                if c[0] == 0 and c[1] == c[2] == c[3]:
                    continue
            ps = bs.copy()
            continue
    res = False
    break

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

Solution (Python):
N = int(input())
List=list(map(int,input().split()))
List.sort()
a = List[0]
b = List.count(a)
c = List[N//3]
d = List.count(c)
e = List[2*N//3]
f = List.count(e)
if a == c and c == e:
    if a == 0 and b == N:
        print('Yes')
    else:
        print('No')
elif c == e:
    if a == 0  and N % 3 == 0 and b == N // 3 and d == 2 * N // 3:
        print('Yes')
    else:
        print('No')
elif N % 3 == 0 and b == N // 3 and d == N //3 and f == N //3 and a ^ e == c : 
    print('Yes')
else:
    print('No')

Solution (Python):


N = int(input())
a_all = list(map(int, input().split()))
t = list(set(a_all))

if len(t)==3:
    if (t[0]^t[1]==t[2]):
        a=0
        b=0
        c=0
        for i in a_all:
            if i==t[0]:
                a+=1
            elif i==t[1]:
                b+=1
            else:
                c+=1
        if a==b and b==c:
            print("Yes")
        else:
            print("No")
    
    else:
        print("No")
    
    
elif len(t)==2:
    a=0
    b=0
    for i in a_all:
        if i==t[0]:
            a+=1
        else:
            b+=1
    if(a == b*2 or  b == a*2):
        print("Yes")
    else:
        print("No")
elif len(t)==1:
    if t[0]^t[0]==t[0]:
        print("Yes")
    else:
        print("No")

else:
    print("No")