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.



Sample input:
3
1 2 3


Sample output:
Yes

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
aDict={}
for key in set(a):
    aDict[key]=0
for ai in a:
    aDict[ai]+=1

canPuton=False
if len(aDict)==1:
    if 0 in aDict.keys():
        canPuton=True

elif len(aDict)==2:
    if 0 in aDict.keys():
        if n%3==0:
            canPuton=True
            for key in aDict:
                if key==0:
                    if aDict[key]!=n//3:
                        canPuton=False
                else:
                    if aDict[key]!=2*n//3:
                        canPuton=False

elif len(aDict)==3:
    a,b,c=aDict.keys()
    if n%3==0:
        if (a^b)==c:
            canPuton=True
            for key in aDict.keys():
                if aDict[key]!=n//3:
                    canPuton=False
if canPuton:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
lista = list(map(int,input().split()))
list2 = []
ans = 0
for i in lista:
    ans = ans^i

ans = str(format(ans,"b"))

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

Submission status: Accepted

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

last = 0

for i in range(N-1) :
    last = last ^ A[i]

if last == A[-1] :
    print('Yes')
else :
    print('No')

Submission status: Accepted

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

a.sort()

b = set(a)

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

if len(b) == 1:
	s = a[0]
	if s^s == s:
		print("Yes")
	else:
		print("No")
	exit()
if N % 3 != 0:
	print("No")
	exit()
n = N//3

if len(b) == 2:
	s = a[0]
	t = a[-1]
	if s^s == t and s^t == s:
		if a.count(s) == 2*n and a.count(t) == n:
			print('Yes')
			exit()
		else:
			print('No')
			exit()
	s,t = [t,s]
	if s^s == t and s^t == s:
		if a.count(s) == 2*n and a.count(t) == n:
			print('Yes')
			exit()
		else:
			print('No')
			exit()
	print('No')
	exit()
if len(b) == 3:
	s,t,u = list(b)
	if s^t == u and s^u == t and t^u == s:
		if a.count(s) == n and a.count(t) == n and a.count(u) == n:
			print('Yes')
			exit()
	print('No')
	exit()
print('No')
exit()

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))

As.sort()
def main():
  if N%3 == 0:
    a, b, c = As[0], As[N//3], As[2*N//3]
    for i in range(0, N//3):
      if a != As[i]:
        return "No"
    for i in range(N//3, 2*N//3):
      if b != As[i]:
        return "No"
    for i in range(2*N//3, N):
      if c != As[i]:
        return "No"
    if a^b == c and b^c == a and c^a == b:
      return "Yes"
    else:
      return "No"
  else:
    if As[0] != As[N-1]:
      return "No"
    else:
      if As[0] == 0:
        return "Yes"
      else:
        return "No"
print(main())

Submission status: Accepted

Solution code:
_input = [i for i in open(0).read().split('\n') if i]
n = int(_input[0])
a = [int(i) for i in _input[1].split()]

import functools
if functools.reduce(lambda a, b: a^b, a) == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/python3

import math
import sys


DEBUG = False


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, A):
    d = {}
    for a in A:
        if a not in d:
            d[a] = 0
        d[a] += 1

    if N % 3 == 0:
        if len(d) > 3:
            return False

        if len(d) == 3:
            a, b, c = d
            if d[a] != d[b] or d[b] != d[c]:
                return False
            arr = [a, b, c]
        elif len(d) == 2:
            a, b = d
            if d[a] * 2 == d[b]:
                arr = [a, b, b]
            elif d[b] * 2 == d[a]:
                arr = [a, a, b]
            else:
                return False
        else:
            (a,) = d
            arr = [a, a, a]

        a, b, c = arr
        if a ^ b == c or a ^ c == b or b ^ c == a:
            return True
        return False

    if len(d) > 1:
        return False

    (a,) = d
    if a != 0:
        return False
    return True


def main():
    N = int(inp())
    A = [int(e) for e in inp().split()]

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(1, n):
    a[0] ^= a[i]

if a[0] == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input().strip())
A = map(int, input().strip().split())

a0 = A.__next__()
tmp = 0
for i, a in enumerate(A):
  tmp ^= a

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = list(set(a))
flag = False
if len(b) == 3:
    if b[0] ^ b[1] == b[2]:
        if a.count(b[0]) == N/3 and a.count(b[1]) == N/3 and a.count(b[2]) == N/3:
            flag = True
if len(b) == 1:
    if b[0] == 0:
        flag = True
if len(b) == 2:
    if 0 in b and a.count(0) == N / 3:
            flag = True


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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=0
a.sort()
if a[0]==0:
    if a.count(a[0])==n:
        s=1
    if n%3==0:
        if (a.count(a[0])==n//3 and a.count(a[n//3])==n//3*2):
            s=1
else:
    if n%3==0:
        if a.count(a[0])==n//3 and a.count(a[n//3])==n//3 and a.count(a[n//3*2])==n//3:
            x=a[0]
            y=a[n//3]
            z=a[n//3*2]
            if x^y==z and y^z==x and z^x==y:
                s=1
if s==1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
an = [int(i) for i in input().split()]
ax = 0
for i in range(n):
  ax ^= an[i]
if ax:
  print('No')
else:
  print('Yes')

Submission status: Accepted

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

cur = A[0]
for a in A[1:]:
    cur ^= a
# print(cur)
print('Yes' if cur==0 else 'No')

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np

N = int(stdin.readline())
a = [int(x) for x in stdin.readline().rstrip().split()]

tmp = None
for i in range(N):
    if i == 0:
        tmp = a[i]
    else:
        tmp = tmp ^ a[i]

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

Submission status: Accepted

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

ans = "No"
cnt = {}
for ai in a:
    if ai in cnt:
        cnt[ai] += 1
    else:
        cnt[ai] = 1
if len(cnt) == 1:
    if 0 in cnt:
        ans = "Yes"
elif len(cnt) == 2:
    k = list(sorted(cnt.keys()))
    if k[0] == 0 and 2 * cnt[0] == cnt[k[1]] and 3 * cnt[0] == n:
        ans = "Yes"
elif len(cnt) == 3:
    v = list(cnt.values())
    k = list(cnt.keys())
    if v[0] == v[1] == v[2] and k[0] ^ k[1] == k[2]:
        ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
import sys

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

from collections import Counter
ac = Counter(a)

if len(ac) == 3 and len(Counter(ac.values())) == 1 and ac.most_common()[0][0]^ac.most_common()[1][0] == ac.most_common()[2][0]:
    print('Yes')
    sys.exit()
if len(ac) == 2 and ac.most_common()[0][1] == ac.most_common()[1][1] * 2 and ac.most_common()[0][0]^ac.most_common()[0][0] == ac.most_common()[1][0]:
    print('Yes')
    sys.exit()
if len(ac) == 1 and ac.most_common()[0][0] == 0:
    print('Yes')
    sys.exit()
print('No')

Submission status: Accepted

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

def f(a, b, c):
    if a ^ b == c and a ^ c == b and b ^ c == a:
        return True
    else:
        return False

if N % 3 != 0:
    x = a[0]
    for i in range(len(a)):
        if a[i] != x:
            print("No")
            exit()
    if f(x, x, x):
        print("Yes")
    else:
        print("No")

else:
    flag = 0
    x = [-1, -1, -1]
    for i in range(len(a)):
        if a[i] not in x:
            if flag == 3:
                print("No")
                exit()

            x[flag] = a[i]
            flag += 1

    if flag == 3:
        if f(x[0], x[1], x[2]) and a.count(x[0]) == a.count(x[1]) == a.count(x[2]):
            print("Yes")
        else:
            print("No")
    elif flag == 1:
        if f(x[0], x[0], x[0]):
            print("Yes")
        else:
            print("No")
    else:
        if a.count(x[0]) == 2 * a.count(x[1]) and f(x[0], x[0], x[1]):
            print("Yes")
        elif a.count(x[1]) == 2 * a.count(x[0]) and f(x[0], x[1], x[1]):
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
N = int(input())

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


ans = a[0]
for i in range(1,N):
    ans = ans ^ a[i]


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

Submission status: Accepted

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

if n % 3 != 0:
    if sum(a) == 0:
        print("Yes")
    else:
        print("No")
else:
    count = {}
    for i in range(n):
        count.setdefault(a[i], 0)
        count[a[i]] += 1
    num = list(count.keys())
    if len(num) > 3:
        print("No")
    elif len(num) == 3:
        if count[num[0]] == count[num[1]] and count[num[1]] == count[num[2]]:
            if num[0] ^ num[1] == num[2] and num[1] ^ num[2] == num[0] and num[2] ^ num[0] == num[1]:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    elif len(num) == 2:
        if count[num[0]] == (n // 3) and count[num[1]] == (n // 3) * 2:
            if num[0] ^ num[1] == num[1] and num[1] ^ num[1] == num[0]:
                print("Yes")
            else:
                print("No")
        elif count[num[0]] == (n // 3) * 2 and count[num[1]] == (n // 3):
            if num[0] ^ num[1] == num[0] and num[0] ^ num[0] == num[1]:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    elif len(num) == 1:
        if num[0] == 0:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

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

if len(set(a)) == 1:
    if a[0] == 0:
        print("Yes")
    else:
        print("No")
elif len(set(a)) == 2:
    b = list(set(a))
    b.sort()
    if a.count(b[0]) == N//3 and N % 3 == 0:
        print("Yes")
    else:
        print("No")

elif len(set(a)) == 3:
    b = list(set(a))
    b.sort()
    if b[0] ^ b[2] == b[1] and a.count(b[0]) == N//3 and a.count(b[1]) == N//3 and N % 3 == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
# input = sys.stdin.readline
# inf = 10 ** 18
# P = 10 ** 9 + 7

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

if N % 3 > 0:
    if a.count(0) == N:
        print('Yes')
    else:
        print('No')
    sys.exit()

items = []
for ai in a:
    if ai not in items: items.append(ai)
    if len(items) >= 3: break
items.sort()

if len(items) == 1:
    if a.count(0) == N:
        print('Yes')
    else:
        print('No')
elif len(items) == 2:
    cnt = [a.count(item) for item in items]
    if sum(cnt) < N:
        print('No')
    if items[0] > 0:
        print('No')
    elif a.count(items[1]) == a.count(0) * 2:
        print('Yes')
    else:
        print('No')
else:
    cnt = [a.count(item) for item in items]
    if sum(cnt) < N:
        print('No')
    elif items[2] != items[0] ^ items[1]:
        print('No')
    elif cnt[0] == cnt[1] == cnt[2]:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
a_list = list(map(int, input().split()))
a_list = np.array(a_list)

if N % 3 != 0:
    if (a_list != 0).any():
        print("No")
    else:
        print("Yes")
    exit()

if (a_list == 0).all():
    print("Yes")
    exit()

keta = 0
while (a_list != 0).any():
    s = (a_list & 1).sum()
    if s != 2 * len(a_list) // 3 and s != 0:
        print("No")
        exit()
    else:
        a_list >>= 1

print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
dict1={}
for i in range(n):
	try:
		dict1[arr[i]]+=1
	except:
		KeyError
		dict1[arr[i]]=1
if(0 in dict1.keys()):
	if(dict1[0]==n):
		print("Yes")
	elif(n%3==0 and dict1[0]==n//3):
		if(len(dict1)==2):
			print("Yes")
		else:
			print("No")
	else:
		print("No")
else:
	if(n%3==0 and len(dict1)==3):
		arr1=[]
		for i in dict1.keys():
			if(dict1[i]!=n//3):
				print("No")
				exit(0)
			arr1.append(i)
		#print(arr1)
		if(arr1[0]^arr1[1]==arr1[2]):
			print("Yes")
		else:
			print("No")
	else:
		print("No")

Submission status: Accepted

Solution code:
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:
        keys = []
        for k in c.keys():
            keys.append(k)

        if keys[0] ^ keys[1] != keys[2]:
            return 'No'

        vals = set()
        for v in c.values():
            vals.add(v)

        if len(vals) == 1:
            return 'Yes'

    return 'No'


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

Submission status: Accepted

Solution code:
import collections
n=int(input())
A=[int(i) for i in input().split()]
AA=collections.Counter(A)
AK=AA.keys()
AV=AA.values()

ans=True
if n%3!=0:
  ans=False
else:
  nn=n//3
  if len(AK)>3:
    ans=False
  elif len(AK)==3:
    a,b,c=AK
    if AA[a]!=nn or AA[b]!=nn or AA[c]!=nn:
      ans=False
    else:
      if a^b!=c or b^c!=a:
        ans=False
  elif len(AK)==2:
    a,b=AK
    if a*b!=0:
      ans=False
    else:
      if a<b:
        a,b=b,a
      if AA[a]!=2*nn or AA[b]!=nn:
        ans=False
  else:
    for a in AK:
      if a!=0:
        ans=False
if len(AK)==1:
  for a in AK:
    if a==0:
      ans=True
print("Yes" if ans==True else "No")

Submission status: Accepted

Solution code:
import math
import fractions

n = list(map(int, input().split()))
n = n[0]
b = list(map(int, input().split()))

b.sort()

if (n%3==0):
    flag = 1
    for i in range(3):
        for j in range(n//3-1):
            if(b[(n//3)*i + j] != b[(n//3)*i + j+1]):
                flag *= 0
            if(b[(n//3)*2]^b[n//3]!=b[0]):
                flag *= 0
    if(flag==1):
        ans="Yes"
    else:
        ans="No"
else:
    if(sum(b)==0):
        ans="Yes"
    else:
        ans="No"
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
a = 0
for i in range(N):
    a = a ^ A[i]

if a == 0:
    output = "Yes"
else:
    output = "No"

print(output)

Submission status: Accepted

Solution code:
#  --*-coding:utf-8-*--

def f(N, A):
    S = {}
    
    for a in A:
        if not a in S:
            S[a] = 1
        else:
            S[a] += 1


    if len(S) == 1:
        if 0 in S:
            return 'Yes'
        else:
            return 'No'
    elif N%3 > 0 or len(S) > 3:
        return 'No'

    keys = list(S)

    if len(keys) == 2:
        if 0 in S and S[0] == N//3:
            return 'Yes'

        return 'No'

    if (keys[0] ^ keys[1]) != keys[2]:
        return 'No'

    if S[keys[0]] != S[keys[1]] or S[keys[0]] != S[keys[2]]:
        return 'No'

    return 'Yes'



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

    print(f(N, A))

 


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for ai in range(len(a) - 1):
    all_xor = all_xor ^ a[ai + 1]

for ai in a:
    if ai ^ all_xor != ai:
        print('No')
        exit(0)

print('Yes')
exit(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import defaultdict

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, a: "List[int]"):
    A = defaultdict(lambda : 0)
    for x in a:
        A[x] += 1
    if len(A) == 1 and 0 in A:
        print(YES)
        return
    if N % 3 != 0:
        print(NO)
        return
    if len(A) == 2 and A[0] == N // 3:
        print(YES)
        return
    if len(A) != 3:
        print(NO)
        return
    L = list(A.keys())
    if L[0] ^ L[1] != L[2]:
        print(NO)
        return
    if A[L[0]] != A[L[1]] or A[L[0]] != A[L[2]]:
        print(NO)
        return
    print(YES)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))

a = l[0]
for i in l[1:]:
    a ^= i

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import os


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

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

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


solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 14 20:27:59 2019

@author: ctiuser
"""
import sys

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

A.sort()

if A[-1] == 0:
    print('Yes')
    sys.exit()

if N % 2 == 0:
    if A[0] == 0:
        flg = True
        if A[0] != A[N//2-1]:
            flg = False
        if A[N//2] != A[-1]:
            flg = False
        if flg:
            print('Yes')
            sys.exit()

flg = True
if N % 3 != 0:
    flg = False

if A[0] != A[N//3-1]:
    flg = False
if A[N//3] != A[(2*N)//3-1]:
    flg = False
if A[(2*N)//3] != A[(3*N)//3-1]:
    flg = False

if A[0] ^ A[N//3] != A[(2*N)//3]:
    flg = False

if flg:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()

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

d = {}
for e in a:
    if e not in d:
        d[e] = 1
    else:
        d[e] += 1

ans = ""


if len(d) > 3:
    ans = "No"
elif len(d) == 1:
    if 0 in d:
        ans = "Yes"
    else:
        ans = "No"
elif N % 3 == 0:
    if len(d) == 2:
        if 0 in d and d[0] == N // 3:
            ans = "Yes"
        else:
            ans = "No"
    elif len(d) == 3:
        keys = list(d.keys())
        if keys[0] ^ keys[1] == keys[2] and d[keys[0]] == N // 3 and d[keys[1]] == N // 3:
            ans = "Yes"
        else:
            ans = "No"
else:
    ans = "No"

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(list(set(a)))
print("Yes"if (len(b)==3 and len(list(set([a.count(i)for i in b])))==1and b[0]^b[1]==b[2])or (len(b)==2 and a.count(0)==n//3 and n%3==0) or(len(b)==1 and b[0]==0)else"No")

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(item) for item in input().split()]
cnt = Counter(a)
length = len(cnt)
if length == 1:
    key = list(cnt.keys())[0]
    if key == key ^ key:
        print("Yes")
    else:
        print("No")
elif length == 2:
    val = []
    for key in cnt.keys():
        val.append(key)
    if cnt[0] == n // 3 and n % 3 == 0:
        print("Yes")
    else:
        print("No")
elif length == 3:
    val = []
    for key in cnt.keys():
        val.append(key)
    if (val[0] ^ val[1] != val[2]) or (val[1] ^ val[2] != val[0]) or (val[2] ^ val[0] != val[1]):
        print("No")
        exit()
    if n % 3 != 0:
        print("No")
        exit()
    if (cnt[val[0]] != n // 3) or (cnt[val[1]] != n // 3) or (cnt[val[2]] != n // 3):
        print("No")
        exit()
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
a=Counter(a)
v=list(a.values())
if len(v)>3:
    print("No")
elif len(v)==1:
    if a[0]>0:
        print("Yes")
    else:
        print("No")
elif n%3!=0:
    print("No")
elif len(v)==2:
    if a[0]==n//3:
        print("Yes")
    else:
        print("No")
else:
    if v==[n//3,n//3,n//3]:
        aa=list(a.keys())
        if aa[0]^aa[1]==aa[2] or aa[0]^aa[2]==aa[1] or aa[1]^aa[2]==aa[0]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=[int(j) for j in input().split()]
import collections
c=collections.Counter(a)
l=c.most_common()
ll=[]
for i,j in l:
    ll.append(i)
if sum(ll)==0:
    print("Yes")
    exit()
if 0 in ll:
    if len(l)==2:
        for i,j in l:
            if i==0:
                z=j
            else:
                t=j
        if 2*z==t:
            print("Yes")
            exit()
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()

p=l[0][1]
q=[]
if len(l)==3:
    for i,j in l:
        if j==p:
            q.append(i)
        else:
            print("No")
            exit()
else:
    print("No")
    exit()
if q[0]^q[1]==q[2] and q[0]^q[2]==q[1] and q[2]^q[1]==q[0]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = input()

a = list(map(lambda x: int(x), input().split()))

xor = 0

for i in a:
    xor = xor ^ i

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

Submission status: Accepted

Solution code:
import os, sys, re, math

N = int(input())

v = list(map(int, input().split(' ')))
s = 0
for i in range(len(v)):
    s = s ^ v[i]

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

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    ans = {}
    for x in a:
        sbin = bin(x)[2:][::-1]
        for i, c in enumerate(sbin):
            if c != '1':
                continue
            if i in ans:
                ans[i] += 1
            else:
                ans[i] = 1
    for x in ans.values():
        if x % 2 != 0:
            print('No')
            return
    print('Yes')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N == 3:
    if A[0]^A[1] == A[2]:
        print('Yes')
    else:
        print('No')
    exit()
a = A[0]
for i in range(1,N):
    a = a ^ A[i]
if a == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

import collections
d = dict(collections.Counter(A))
ans = "No"
num = list(d.keys())
num.sort()
if len(d) == 1:
    if num[0] == 0:
        ans = "Yes"
elif len(d) == 2:
    if num[0] == 0 and d[0] * 3 == N:
        ans = "Yes"
elif len(d) == 3:
    if num[0] ^ num[1] == num[2] and d[num[0]] == d[num[1]] and d[num[2]] == d[num[1]]:
        ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
setA = list(set(A))
if len(setA) == 1 and setA[0] == 0:
	print("Yes")
	exit()
if N % 3 != 0:
	print("No")
	exit()
if len(setA) == 1 or len(setA) > 3:
	print("No")
	exit()
if len(setA) == 2:
	if 0 in setA:
		setA.sort()
		if A.count(0) == N // 3 and A.count(setA[1]) == (N // 3) * 2:
			print("Yes")
			exit()
	print("No")
	exit()

if setA[0] ^ setA[1] != setA[2]:
	print("No")
	exit()
for a in setA:
	if A.count(a) != N // 3:
		print("No")
		exit()
print("Yes")
exit()

Submission status: Accepted

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

if N%3:
  if all([a==0 for a in A]):
    print('Yes')
  else:
    print('No')


else:
  c = Counter(A)
  temp = 0
  for k,v in c.items():
    if v % (N//3):
      print('No')
      exit()
    else:
      for i in range(v//(N//3)):
        temp = temp^k
  if temp==0:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter

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

res = 'Yes'

a_dict = Counter(a_list)


a_keys = list(a_dict.keys())
if len(a_keys) > 3:
    res = 'No'
elif len(a_keys) == 3:
    a, b, c = a_keys
    if a_dict[a] != a_dict[b]:
        res = 'No'
    if a_dict[a] != a_dict[c]:
        res = 'No'
    if a ^ b != c:
        res = 'No'
    if b ^ c != a:
        res = 'No'
    if c ^ a != b:
        res = 'No'
elif len(a_keys) == 2:
    a, b = a_keys
    if a_dict[a] == 2 * a_dict[b]:
        if b != 0:
            res = 'No'
    elif 2 * a_dict[a] == a_dict[b]:
        if a != 0:
            res = 'No'
    else:
        res = 'No'
else:
    a = a_keys[0]
    if a != 0:
        res = 'No'
print(res)

Submission status: Accepted

Solution code:
n = input()
alist = list(map(int,input().split()))

sum = 0
for a in alist:
    sum ^= a

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

Submission status: Accepted

Solution code:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


N = int(input())
a = list(map(int,input().split()))
C = Counter(a)
if len(C)>=4:
    print("No")
elif len(C)==1:
    if a[0]==0:
        print("Yes")
    else:
        print("No")
elif len(C)==2:
    key=[]
    for k in C.keys():
        key.append(k)
    key.sort()
    if key[0]==0 and C[key[1]] == 2*C[key[0]]:
        print("Yes")
    else:
        print("No")
elif len(C)==3:
    val = []
    key = []
    for k in C.keys():
        key.append(k)
    if key[0] ^ key[1] != key[2]:
        print("No")
        exit()
    for v in C.values():
        val.append(v)
    if val[0]==val[1]==val[2]:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    if len(C) == 1 and 0 in C:
        print("Yes")
        return
    if N % 3 != 0:
        print("No")
        return
    if 0 in C and len(C) == 2:
        if C[0] * 3 == N:
            print("Yes")
            return
    elif 0 not in C and len(C) == 3:
        for c in C:
            if C[c] * 3 != N:
                print("No")
                return
            X = list(C)
            if X[0] ^ X[1] != X[2]:
                print("No")
                return
            print("Yes")
            return
    print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]

a = A[0]^A[1]
for i in range(2, n):
    a = a ^ A[i]

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

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
if 0 not in l:
    dic={}
    ll=[]
    for i in l:
        if i not in ll:
            ll.append(i)
            dic[i]=1
        else:
            dic[i]+=1
        if len(ll)>3:
            break
    if len(ll)==3:
        x,y,z=ll[0],ll[1],ll[2]
        nx,ny,nz=dic[x],dic[y],dic[z]
        if max(nx,ny,nz)-min(nx,ny,nz)<=1 and x^y==z:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    l.sort()
    if l[-1]==0:
        print("Yes")
    else:
        cnt=l.count(l[-1])
        zcnt=n-cnt
        if n%3==0:
            if cnt==zcnt*2:
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if zcnt==(n+2)//3 or zcnt==(n-1)//3:
                print("Yes")
            else:
                print("No")
        else:
            if zcnt==(n+1)//3 or zcnt==(n-2)//3:
                print("Yes")
            else:
                print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
ans=a[0]
for i in range(1,n):
    ans=ans^a[i]
if ans==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def xor_circle(N: int, A: list)->bool:
    M = max(A)

    b = 1
    while b <= M:
        zero, one = 0, 0
        for a in A:
            if a & b:
                one += 1
            else:
                zero += 1

        if one != 2 * zero and one != 0:
            return False
        b <<= 1

    return True


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]

    yes = xor_circle(N, A)
    print('Yes' if yes else 'No')