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
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

from collections import Counter

def main():
    N = i2n()
    A = i2nn()
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    c = Counter(A)
    k = list(c.keys())
    v = list(c.values())
    if len(c) == 1:
        if k[0] == 0:
            print('Yes')
            return
    if len(c) == 2:
        if k[0] == 0 and v[0] * 2 == v[1]:
            print('Yes')
            return
        if k[1] == 0 and v[1] * 2 == v[0]:
            print('Yes')
            return
    if len(c) == 3:
        if k[0] ^ k[1] ^ k[2] == 0:
            if v[0] == v[1] and v[1] == v[2]:
                print('Yes')
                return
    print('No')

main()

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

d = {}
for num in a:
    d.setdefault(num, 0)
    d[num] += 1

keys = sorted(d.keys())
if len(keys) == 1 and keys[0] == 0:
    print('Yes')
elif len(keys) == 2 and d[0] * 2 == d[keys[1]]:
    print('Yes')
elif len(keys) == 3 and d[keys[0]] == d[keys[1]] == d[keys[2]] and keys[0] ^ keys[1] ^ keys[2] == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
flag = True
if max(a) == 0:   
    flag = True
else:
    if N % 3 != 0:   
        flag = False
    else:
        n = N // 3
        a_set = set(a)
        if len(a_set) == 2:
            count = [] 
            value = []
            for number in a_set:
                count.append(a.count(number))
                value.append(number)
            if value[0] == 0 and count[0] == n and count[1] == n * 2:
                flag = True
            else:
                flag = False
        elif len(a_set) == 3:
            count = []
            value = []
            for number in a_set:
                count.append(a.count(number))
                value.append(number)
            if count[0] == count[1] == count[2]:
                if value[0] ^ value[1] ^ value[2] == 0:
                    flag = True
                else:
                    flag = False
            else:
                flag = False
        else:
            flag = False
if flag:
    print('Yes')
else:
    print('No')

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

a = list(set(A))

ans = "No"

if a == [0]:
    ans = "Yes"
elif len(a) == 2:
    if (a[0] == 0 or a[1] == 0) and N % 3 == 0 and A.count(0) == N//3:
        ans = "Yes"
elif len(a) == 3:
    if a[0] ^ a[1] == a[2] and N % 3 == 0 and A.count(a[0]) == A.count(a[1]) == N//3:
        ans = "Yes"

print(ans)

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

a = list(set(A))

ans = "No"

if a == [0]:
    ans = "Yes"
elif len(a) == 2:
    if N % 3 == 0 and A.count(0) == N//3:
        ans = "Yes"
elif len(a) == 3:
    if a[0] ^ a[1] == a[2] and N % 3 == 0 and A.count(a[0]) == A.count(a[1]) == N//3:
        ans = "Yes"

print(ans)

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

a = list(set(A))

ans = "No"

if len(a) == 1:
    if a == [0]:
        ans = "Yes"
elif len(a) == 2:
    if N % 3 == 0 and A.count(0) == N//3:
        ans = "Yes"
elif len(a) == 3:
    if a[0] ^ a[1] == a[2] and N % 3 == 0 and A.count(a[0]) == A.count(a[1]) == N//3:
        ans = "Yes"

print(ans)

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

a = list(set(A))

ans = "No"

if len(a) == 1:
    if a == [0]:
        ans = "Yes"
elif len(a) == 2:
    if N % 3 == 0 and A.count(0) == N//3:
        ans = "Yes"
elif len(a) == 3:
    if a[0] ^ a[1] ^ a[2] == 0 and N % 3 == 0 and (A.count(a[0]),A.count(a[1])) == (N//3,N//3):
        ans = "Yes"

print(ans)

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

a = list(set(A))

ans = "No"

if len(a) == 1:
    if a == [0]:
        ans = "Yes"
elif len(a) == 2:
    if N % 3 == 0 and A.count(0) == N//3:
        ans = "Yes"
elif len(a) == 3:
    if a[0] ^ a[1] ^ a[2] == 0 and N % 3 == 0 and (A.count(a[0]),A.count(a[1]),A.count(a[2])) == (N//3,N//3,N//3):
        ans = "Yes"

print(ans)

Solution (Python):
"""
x -> y -> x^y ->
x -> y -> x^y

3つ周期。
N%3 != 0 x=y=x^yなので、全部0
N%3 == 0 x,y,x^yが同数存在
"""

N = int(input())
As = list(map(int, input().split()))
numset = sorted(list(set(As)))
n = len(numset)
if n == 1:
    if sum(As) == 0: print("Yes")
    else:print("No")
elif n == 2:
    n1 = As.count(numset[0])
    n2 = As.count(numset[1])
    if 2*n1 == n2 and numset[0] == 0: print("Yes")
    else:print("No")
elif n == 3:
    n1 = As.count(numset[0])
    n2 = As.count(numset[1])
    n3 = As.count(numset[2])
    if n1 == n2 == n3 and (numset[0]^numset[1]^numset[2])==0: print("Yes")
    else: print("No")
else:
    print("No")

Solution (Python):
import sys
from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]
ct = Counter(a).most_common()
num = len(ct)

if num == 1:
	print('Yes' if ct[0][0] == 0 else 'No')
elif num == 2:
	if N % 3 == 0:
		if ct[0][0] != 0 and ct[0][1] == 2*N//3:
			if ct[1][0] == 0 and ct[1][1] == N//3:
				print('Yes')
				sys.exit()
	print('No')
elif num == 3:
	if N % 3 == 0:
		if ct[0][1] == ct[1][1] == ct[2][1]:
			if ct[0][0]^ct[1][0]^ct[2][0] == 0:
				print('Yes')
				sys.exit()
		
	print('No')
else:
	print('No')

Solution (Python):
import sys
from collections import Counter

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    c = Counter(A)
    
    if 0 in c and len(c) == 1:
        return 'Yes'

    
    if 0 in c and len(c) == 2:
        v0 = c[0]
        for k, v in c.items():
            if k != 0 and v == 2 * v0:
                return 'Yes'

    
    if len(c) == 3:
        x, y, z = tuple(c.keys())
        if (x ^ y) == z and c[x] == c[y] == c[z]:
            return 'Yes'

    return 'No'


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

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

tmp = 0
for data in a:
    tmp = tmp ^ data

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

Solution (Python):
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
t=N//3
ans="No"
if all(a==0 for a in A):
  ans="Yes"
elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:t]):
    ans="Yes"     
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==t and A.count(AA[t])==t:
    if AA[0]^AA[t]==AA[2*t] and AA[t]^AA[2*t]==AA[0] and AA[2*t]^AA[0]==AA[t]:
      ans="Yes"   
print(ans)

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

cnt=[0]*30
n=int(input())
a=[int(i) for i in input().split()]
for i in a:
    x=(bin(i)[2:])[::-1]
    for j,k in enumerate(x):
        if k=="1":
            cnt[j]=(cnt[j]+1)%2

print("No" if any(cnt) else "Yes")

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

if N%3:
    ans = True
    for a in A:
        if a:ans=False;break
else:
    B = set(A)
    l = len(B)
    ans = True
    if l>3:
        ans = False
    elif l==1:
        for b in B:
            if b:ans=False;break
    else:
        if l==3:
            a,b,c = B
            l,m,n = (A.count(x) for x in (a,b,c))
        if l==2:
            a,b = B
            l,m = (A.count(x) for x in (a,b))
            if l>=m:
                c=a
                n=l//2
                l-=n
            else:
                c=b
                n=m//2
                m-=n
        ans = ans and (l==m==n==N//3) and (a^b==c)
        
if ans:print("Yes")
else:print("No")

Solution (Python):


n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in range(1,n):
    ans=ans^a[i]

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

Solution (Python):
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
ans="No"


if all(a==0 for a in A):
  ans="Yes"



elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:third]):
    ans="Yes"



elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if AA[0]^AA[third]==AA[2*third] and \
    AA[third]^AA[2*third]==AA[0] and \
    AA[2*third]^AA[0]==AA[third]:
      ans="Yes"   
print(ans)

Solution (Python):
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
ans="No"
if all(a==0 for a in A):
  ans="Yes"
elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:third]):
    ans="Yes"     
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if AA[0]^AA[third]==AA[2*third] and \
    AA[third]^AA[2*third]==AA[0] and \
    AA[2*third]^AA[0]==AA[third]:
      ans="Yes"   
print(ans)

Solution (Python):
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
answer="No"

if all(a==0 for a in A):
  answer="Yes"

elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:third]):
    answer="Yes"
     
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if bin(AA[0]^AA[third])==bin(AA[2*third]) and \
    bin(AA[third]^AA[2*third])==bin(AA[0]) and \
    bin(AA[2*third]^AA[0])==bin(AA[third]):
      answer="Yes"
    
print(answer)

Solution (Python):
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
answer="No"


if all(a==0 for a in A):
  answer="Yes"



elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:third]):
    answer="Yes"
     


elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if bin(AA[0]^AA[third])==bin(AA[2*third]) and \
    bin(AA[third]^AA[2*third])==bin(AA[0]) and \
    bin(AA[2*third]^AA[0])==bin(AA[third]):
      answer="Yes"
    
print(answer)

Solution (Python):
N = input()
xor = 0
for i in map(int, input().split()):
    xor ^= i
print(xor == 0 and 'Yes' or 'No')

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

c = Counter(a)
keys = sorted(list(c.keys()))
values = sorted(list(c.values()))
if len(c) == 1 and c[0] == N:
    print("Yes")
    exit()
if N % 3 != 0:
    print("No")
elif len(c) == 2 and 0 in keys and c[0] == N//3:
    print("Yes")
elif len(c) == 3 and values[0] == values[1] == values[2] == N//3 and keys[0] ^ keys[1] ^ keys[2] == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ret = 'No'
c = Counter(A)
if all([i == 0 for i in c]):
    ret = 'Yes'
else:
    v = set(list([i[1] for i in c.items()]))
    if len(c) == 3 and all([i == N/3 for i in v]):
        c = list(c)
        if c[0] ^ c[1] == c[2]:
            ret = 'Yes'
    elif len(c) == 2 and 0 in c:
        for i in c.items():
            if i[0] == 0 and i[1] == N/3:
                ret = 'Yes'

print(ret)

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

def all_zero(a):
    for e in a:
        if e != 0:
            return False
    return True

def three_mod_same(a):
    counts = {}
    for e in a:
        if e not in counts:
            counts[e] = 1
        else:
            counts[e] += 1

    for v in counts.values():
        if v != len(a) // 3:
            return False
    return True

def two_elem_one_zero(a):
    if len(set(a)) != 2:
        return False
    counts = {}
    for e in a:
        if e not in counts:
            counts[e] = 1
        else:
            counts[e] += 1
            
    for key, v in counts.items():
        if key == 0:
            if v != len(a) // 3:
                return False
        else:
            if v != (len(a) // 3) * 2:
                return False
    return True

if len(set(a)) != 3:
    if all_zero(a) or ((len(a) % 3 == 0) and two_elem_one_zero(a)):
        print("Yes")
    else:
        print("No")
else:
    p = itertools.permutations(list(set(a)), 3)
    yes = False
    for permed_a in p:            
        good_perm = True
        for i in range(3):
            if permed_a[(i + 1) % 3] != (permed_a[i] ^ permed_a[(i + 2) % 3]):
                good_perm = False
                break
        if good_perm:
            yes = True
            break
    if not yes:
        print("No")
    else:
        if three_mod_same(a):
            print("Yes")
        else:
            print("No")

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

tmp = set()
for a in a_list:
    tmp.add(a)

if a_list.count(0) == N:
    print("Yes")
else:
    if len(tmp) == 2 and a_list.count(0) == N // 3:
        print("Yes")
    elif len(tmp) == 3 and a_list.count(0) == 0:
        b = list(tmp)
        if b[0] ^ b[1] == b[2] and a_list.count(b[0]) == N // 3 \
                and a_list.count(b[1]) == N // 3 and a_list.count(b[2]) == N // 3:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Solution (Python):
from collections import Counter

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


if 0 in da and da[0]==N:
  print('Yes')
elif N%3!=0:
  print('No')
elif len(da)==2 and 0 in da and da[0]==N/3:
  print('Yes')
elif len(da)==3:
  x, y, z = da.keys()
  if (x^y==z) and da[x]==N/3 and da[y]==N/3:
    print('Yes')
  else:
    print('No')
else:
  print('No')

Solution (Python):
from collections import Counter


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


def main():
    if all(map(lambda e: e == 0, a)):
        print('Yes')
        return

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

    count = dict(Counter(a))
    keys = list(count.keys())
    values = list(count.values())
    
    if len(count) == 3:
        if values[0] == values[1] and values[1] == values[2] and (keys[0] ^ keys[1] ^ keys[2]) == 0:
            print('Yes')
        else:
            print('No')
    
    elif len(count) == 2:
        if 0 not in count:
            print('No')
        elif (2 * count[0]) == max(values):
            print('Yes')
        else:
            print('No')
    
    else:
        print('No')


if __name__ == "__main__":
    main()

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

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

Solution (Python):
from collections import Counter
N, *a = map(int, open(0).read().split())

cnt = 0
for v in set(a):
    cnt ^= v

ctr = Counter(a)
flg1 = sum(a) == 0
flg2 = len(ctr) == 2 and ctr[0] == N // 3
flg3 = cnt == 0 and len(ctr) == 3 and all(v == N // 3 for v in ctr.values())
print('Yes' if flg1 or flg2 or flg3 else 'No')

Solution (Python):
N = int(input())
lst = list(map(int, input().split()))
lst.sort()
if lst[0] == 0 and lst[N-1] == 0:
    print ('Yes')
    exit()
if N%3 != 0:
    print ('No')
    exit()

if lst[0] ^ lst[N//3] != lst[(N//3) * 2]:
    print ('No')
    exit()

for i in range(1, N//3):
    if lst[i-1] != lst[i]:
        print ('No')
        exit()

for i in range(1 + N//3, (N//3) * 2):
    if lst[i-1] != lst[i]:
        print ('No')
        exit()

for i in range(1 + (N//3) * 2, (N//3) * 3):
    if lst[i-1] != lst[i]:
        print ('No')
        exit()
print ('Yes')

Solution (Python):

from functools import reduce

n = int(input())

camels = list(map(int, input().split()))


if all(map(lambda x: x == 0, camels)):
    print('Yes')

elif n % 3 == 0 and len(set(camels)) == 2 and camels.count(0) == n // 3:
    print('Yes')

elif n % 3 == 0 and len(set(camels)) == 3 \
        and reduce(lambda x, y: x ^ y, set(camels)) == 0 \
        and camels.count(sorted(set(camels))[0]) == n // 3 \
        and camels.count(sorted(set(camels))[1]) == n // 3:
    print('Yes')
else:
    print('No')

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

bits = [0 for x in range(len(bin(max(A))[2:]))]
for i in range(len(A)):
  ptr = 0
  while A[i] > 0:
    bits[ptr] += A[i] % 2
    A[i] >>= 1
    ptr += 1
for i in range(len(bits)):
  if bits[i] % 2 == 1:
    print("No")
    break
else:
  print("Yes")

Solution (Python):

from functools import reduce

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

if reduce(lambda x, y: x ^ y, camels) == 0:
    print('Yes')
else:
  print('No')

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

c = collections.Counter(a)
key = list(c.keys())
if (c[0] == n or (len(key)==2 and c[0] == n/3) or (len(key)==3 and (key[0] ^ key[1] ^ key[2] == 0) and (c[key[0]] == c[key[1]] == c[key[2]]))):
    print("Yes")
else:
    print("No")

Solution (Python):

import sys
from bisect import bisect_left
from collections import Counter
INF = float("inf")


def yes():
    print("Yes")  


def no():
    print("No")  


def solve(N: int, a: "List[int]"):
    cnt = Counter(a)
    v = list(cnt.values())
    b = list(cnt.keys())
    if len(cnt) == 3:
        if all([x == v[0] for x in v]):
            if b[0] ^ b[1] == b[2] or b[0] ^ b[2] == b[1]:
                yes()
                return
    elif len(cnt) == 2:
        if b[0] != 0:
            b[1], b[0] = b[0], b[1]
        if b[0] == 0 and cnt[b[1]] == cnt[b[0]]*2:
            yes()
            return

    elif len(cnt) == 1:
        if b[0] == 0:
            yes()
            return

    no()
    return

    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, a)


if __name__ == '__main__':
    main()

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

if a.count(0)==n:
    print('Yes')
elif n%3==0:
    if a.count(0)==n//3 and a.count(a[n//3])==n//3*2:
        print('Yes')
    elif a.count(a[0])==n//3 and a.count(a[n//3])==n//3 and a.count(a[n//3*2])==n//3 and a[0]^a[n//3]^a[n//3*2]==0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Solution (Python):
import collections, itertools
N = int(input())
A = [int(_) for _ in input().split()]
C = sorted(collections.Counter(A).most_common(), key=lambda xs: -xs[1])
f = 0
if len(C) == 1:
    a, la = C[0]
    
    if a == 0:
        f = 1
elif len(C) == 2:
    a, la = C[0]
    b, lb = C[1]
    
    if la == lb * 2 and b == 0:
        f = 1
elif len(C) == 3:
    a, la = C[0]
    b, lb = C[1]
    c, lc = C[2]
    
    if la == lb == lc and a ^ b == c:
        f = 1
if f:
    print('Yes')
else:
    print('No')

Solution (Python):
import collections, itertools
N = int(input())
A = [int(_) for _ in input().split()]
C = sorted(collections.Counter(A).most_common(), key=lambda xs: -xs[1])
f = 0
if len(C) == 1:
    a, la = C[0]
    
    if a ^ a == a:
        f = 1
elif len(C) == 2:
    a, la = C[0]
    b, lb = C[1]
    
    if la == lb and a ^ b == a and b ^ a == b:
        f = 1
    
    if la == lb * 2 and b ^ a == a and a ^ a == b:
        f = 1
elif len(C) == 3:
    a, la = C[0]
    b, lb = C[1]
    c, lc = C[2]
    
    if la == lb == lc and any(
            x ^ y == z for x, y, z in itertools.permutations((a, b, c))):
        f = 1
    
    if la == lb == lc + 1:
        if any(x ^ y == c == x and y ^ c == x and c ^ x == y
               for x, y in ((a, b), (b, a))):
            f = 1
    
    if lb == lc == la - 1:
        if any(a ^ y == z and y ^ z == a and z ^ a == y == a
               for y, z in ((b, c), (c, b))):
            f = 1
if f:
    print('Yes')
else:
    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] or any(len(set(a[i:i + m])) > 1 for i in range(0, n, m)):
        ans = 'No'
    else:
        ans = 'Yes'
print(ans)

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):
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(a[i] != a[i - 1] for i in range(1, n) if m != i != 2 * m):
        ans = 'No'
    else:
        ans = 'Yes'
print(ans)

Solution (Python):
from functools import reduce
from operator import xor

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 reduce(xor, a[::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):
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):
from functools import reduce
from operator import xor

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 reduce(xor, a[::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):
N=int(input())
A=list(map(int,input().split()))
d={}
for a in A:
    if a in d:
        d[a]+=1
    else:
        d[a]=1
a=0
if len(d)==1 and 0 in d:
    a=1
elif len(d)==2:
    k=sorted(d.keys(),key=lambda x:d[x])
    if k[1]^k[1]==k[0] and d[k[0]]*2==d[k[1]]:
        a=1
elif len(d)==3:
    k=list(d.keys())
    if k[0]^k[1]==k[2] and d[k[0]]==d[k[1]]==d[k[2]]:
        a=1
print(['No','Yes'][a])

Solution (Python):
def a_xor_circle(N, A):
    """
    N枚の帽子のそれぞれには整数 a_i が書かれている。
    円環状に並んだN頭のラクダのそれぞれに1枚ずつ帽子を被せたい。
    どのラクダについても以下の条件が成立するような帽子の被せ方が存在するか判定せよ。
    ・両隣のラクダが被っている帽子に書かれた数のbitwise-xorが自身の被る帽子の値と等しい

    条件より、x_{i+1} = x_i ^ x_{i+2} で、両辺に x_{i+1} との排他的論理和を取ると
    x_i ^ x_{i+1} ^ x_{i+2} = 0 が成立する。同じことをして、
    x_{i+1} ^ x_{i+2} ^ x_{i+3} = 0 が成立する。この2つの式の両辺それぞれ
    排他的論理和を取ると、 x_i ^ x_{i+3} = 0 すなわち x_i = x_{i+3} である。
    だから、以下の場合、条件を満たす被せ方がある。
    ・全部の帽子の数が0 (この場合、ラクダの数は関係ない)
    ・xが書かれた帽子 : 0が書かれた帽子 = 2 : 1 (x, x, 0 を並べる)
    ・x^y^z=0 となる相異なる3整数が 1:1:1 の割合 (x, y, z を並べる)
    """
    from collections import Counter
    num_count = Counter(A)
    if len(num_count) == 1:
        
        return 'Yes' if num_count[0] != 0 else 'No'
    elif len(num_count) == 2:
        
        count_zero = 0
        for k, v in num_count.items():
            if k == 0:
                count_zero = v
            else:
                count_other = v
        return 'Yes' if count_other == 2 * count_zero else 'No'
    elif len(num_count) == 3:
        
        x, y, z = num_count.keys()
        count_x, count_y, count_z = num_count.values()
        cond = (x ^ y ^ z == 0, count_x == count_y and count_y == count_z)
        return 'Yes' if all(cond) else 'No'
    return 'No'

N = int(input())
A = [int(i) for i in input().split()]
print(a_xor_circle(N, A))

Solution (Python):
def a_xor_circle(N, A):
    """
    N枚の帽子のそれぞれには整数 a_i が書かれている。
    円環状に並んだN頭のラクダのそれぞれに1枚ずつ帽子を被せたい。
    どのラクダについても以下の条件が成立するような帽子の被せ方が存在するか判定せよ。
    ・両隣のラクダが被っている帽子に書かれた数のbitwise-xorが自身の被る帽子の値と等しい

    条件より、x_{i+1} = x_i ^ x_{i+2} で、両辺に x_{i+1} との排他的論理和を取ると
    x_i ^ x_{i+1} ^ x_{i+2} = 0 が成立する。同じことをして、
    x_{i+1} ^ x_{i+2} ^ x_{i+3} = 0 が成立する。この2つの式の両辺それぞれ
    排他的論理和を取ると、 x_i ^ x_{i+3} = 0 すなわち x_i = x_{i+3} である。
    だから、以下の場合、条件を満たす被せ方がある。
    ・全部の帽子の数が0 (この場合、ラクダの数は関係ない)
    ・xが書かれた帽子 : 0が書かれた帽子 = 2 : 1 (x, x, 0 を並べる)
    ・x^y^z=0 となる相異なる3整数が 1:1:1 の割合 (x, y, z を並べる)
    """
    from collections import Counter
    num_count = Counter(A)
    if len(num_count) == 1:
        return 'Yes' if num_count[0] != 0 else 'No'
    elif len(num_count) == 2:
        if num_count[0] == 0:
            return 'No'
        for k, v in num_count.items():
            if k == 0:
                count_zero = v
            else:
                count_other = v
        return 'Yes' if count_other == 2 * count_zero else 'No'
    elif len(num_count) == 3:
        x, y, z = num_count.keys()
        count_x, count_y, count_z = num_count.values()
        if x ^ y ^ z != 0:
            return 'No'
        if count_x != count_y or count_y != count_z or count_z != count_x:
            return 'No'
        return 'Yes'
    else:
        return 'No'
    return None

N = int(input())
A = [int(i) for i in input().split()]
print(a_xor_circle(N, A))

Solution (Python):
_,b=open(0);a=0
for b in b.split():a^=int(b)
print('YNeos'[a>0::2])

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

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

    cnt = Counter(A).most_common()
    n = N // 3
    l = len(cnt)
    if l == 1:
        if cnt[0][0] == 0:
            print('Yes')
        else:
            print('No')
        return
    if l == 2:
        if cnt[1][0] == 0 and cnt[1][1] == n:
            print('Yes')
        else:
            print('No')
        return
    if l > 3 or N % 3:
        print('No')
        return

    if cnt[0][0] ^ cnt[1][0] == cnt[2][0] and cnt[0][1] == cnt[1][1] == n:
        print('Yes')
    else:
        print('No')

input = lambda: stdin.readline()
main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
if all(map(lambda x:x==0,A)) or (sum(map(lambda x:x==0,A))==(N/3) and (len(set(A))==2) or (len(set(A))==3) and list(set(A))[0]^list(set(A))[1]^list(set(A))[2]==0 and A.count(list(set(A))[0])==A.count(list(set(A))[1]) and A.count(list(set(A))[1])==A.count(list(set(A))[2]) and A.count(list(set(A))[2])==A.count(list(set(A))[0])):
    print("Yes")
else:
    print("No")

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

l = len(set(a_list))

def check():
    counter = Counter(a_list)
    if l == 1:
        if a_list[0] == 0:
            return True
        return False
    if l == 2:
        if counter[0] == N/3:
            return True
        return False
    if l == 3:
        x,y,z = set(a_list)
        if int(bin(x^y^z), 0) == 0 and set(list(counter.values()))==set([N/3]):
            return True
        return False
    return False

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
a=1
for i in A:
    a^=i
print(["No","Yes"][a==1])

Solution (Python):


import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

if all([a==0 for a in A]):
    Yes()
    exit()

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

C=Counter(A)
if len(C.keys())==2:
    for k, v in C.items():
        if k==0:
            if v!=N//3:
                No()
                exit()
        else:
            if v!=N//3*2:
                No()
                exit()
    Yes()
elif len(C.keys())==3:
    xor=0
    for k, v in C.items():
        xor^=k
        if v!=N//3:
            No()
            exit()
    if xor==0:
        Yes()
    else:
        No()
else:
    No()

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
l = len(set(a))
if l > 3:
	print("No")
elif l == 1:
	if a[0] == 0:
		print("Yes")
	else:
		print("No")
elif n%3 != 0:
	print("No")
elif l == 2:
	if 0 not in set(a):
		print("No")
	elif a.count(0) == n//3:
		print("Yes")
	else:
		print("No")
else:
	for x in list(set(a)):
		if a.count(x) != n//3:
			print("No")
			break
	else:
		if list(set(a))[0] ^ list(set(a))[1] == list(set(a))[2]:
			print("Yes")
		else:
			print("No")

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

end_frg = 0
ans = 'No'

if sum(a) == 0:
    ans = 'Yes'

elif a.count(0) == n/3 and len(set(a)) == 2:
    ans = 'Yes'

elif len(set(a)) == 3:
    [a0, a1, a2] = set(a)
    if bin(a0 ^ a1 ^ a2) == bin(0):
        if a.count(a0)==a.count(a1)==a.count(a2):
            ans = 'Yes'

print(ans)

Solution (Python):
size = int(input())
nums = list(map(int, input().split()))




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


if len(numu) == 2 \
    and nums.count(0) != 0 \
    and nums.count(0) * 3 == size:
  print("Yes")
  quit()

if len(numu) == 3:
  if nums.count(0) == 1:
    print("No")
    quit()

  if not nums.count(numu[0]) == nums.count(numu[1]) == nums.count(numu[2]):
    print("No")
    quit()

  if numu[0] ^ numu[2] == numu[1] \
      and numu[1] ^ numu[0] == numu[2] \
      and numu[2] ^ numu[1] == numu[0]:
    print("Yes")
    quit()

print("No")