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:
inp = input()
n = int(inp)
inp = input()
split_inp = inp.split()
# if n % 3 != 0:
#     print("No")
#     exit()
# 数字を3つのグループに分けていく．
# 3種類以上の数字があればno
numbers = {}
for str_number in split_inp:
    int_number = int(str_number)
    if int_number not in numbers:
        numbers[int_number] = 1
    else:
        numbers[int_number] += 1
    if len(numbers) > 3:
        print("No")
        exit()
# 二つのグループに分かれていれば数の大きいほうを分割する必要がある
if len(numbers) == 2:
    number_values = [i for i in numbers.values()]
    max_number = max(number_values[0], number_values[1])
    small_number = min(number_values[0], number_values[1])
    if small_number * 2 != max_number:
        print("No")
        exit()
    n_list = []
    for item in numbers.items():
        if item[1] == small_number:
            n_list.append(item[0])
        else:
            n_list.append(item[0])
            n_list.append(item[0])
elif len(numbers) == 3:
    # 均等に3当分されている
    number_list = [i for i in numbers.values()]
    if number_list[0] != number_list[1] or number_list[1] != number_list[2]:
        print("No")
        exit()
    n_list = [i for i in numbers.keys()]
else:
    number_key = [i for i in numbers.keys()]
    for key in number_key:
        if key != 0:
            print("No")
            exit()
    print("Yes")
    exit()


def number_count(k1, k2, k3, count_n):
    count = 0
    if k1 == count_n:
        count += 1
    if k2 == count_n:
        count += 1
    if k3 == count_n:
        count += 1
    return count


# ビット列に同時に直す.下の桁から見ていき，0,1,1になっていなければno

n1 = int(n_list[0])
n2 = int(n_list[1])
n3 = int(n_list[2])
while n1 != 0 or n2 != 0 or n3 != 0:
    # 一番下の桁を取り出す
    c1 = n1 % 2
    c2 = n2 % 2
    c3 = n3 % 2
    n1 = n1 // 2
    n2 = n2 // 2
    n3 = n3 // 2
    # 1,1,0の組み合わせでなければno
    count1 = number_count(c1, c2, c3, 1)
    count0 = number_count(c1, c2, c3, 0)
    if (count1 != 2 or count0 != 1) and count0 != 3:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())
A = deque(map(int, input().split()))
first = A.popleft()


def round(a):
        B = list(A)
        eval = 0
        pre = first
        post = a
        B.remove(a)
        num = N - 2
        while num != 0:
                c = pre ^ post
                try:
                        B.remove(c)
                        pre = post
                        post = c
                        num -= 1
                except:
                        return 0
                        eval = 1
                        break
        
        if eval == 0 and post ^ first == a:
                return 1
        elif eval == 0:
                return 0

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

if val != 0:
        print('No')
else:
        ans = 0
        for i in range(0, N - 1):
                ans = round(A[i])
                if ans == 1:
                        print('Yes')
                        break
                        

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

N = int(input().strip())
As = list(map(int, input().strip().split(' ')))
candidates = list(set(As))

if len(candidates) == 1:
    if candidates[0] == 0:
        print('Yes')
    else:
        print('No')
elif len(candidates) == 2:
    a, zero = candidates
    if a < zero:
        a, zero = zero, a

    if zero == 0:
        count_a = 0
        count_zero = 0
        for element in As:
            if element == a:
                count_a += 1
            elif element == zero:
                count_zero += 1
        else:
            if count_a == count_zero * 2:
                print('Yes')
            else:
                print('No')
    else:
        print('No')
elif len(candidates) > 3:
    print('No')
else:
    a, b, c = candidates[0], candidates[1], candidates[2]
    if a ^ b != c:
        print('No')
    else:
        count_a = 0
        count_b = 0
        count_c = 0
        for element in As:
            if element == a:
                count_a += 1
            elif element == b:
                count_b += 1
            elif element == c:
                count_c += 1
        else:
            if count_a == count_b == count_c:
                print('Yes')
            else:
                print('No')

Submission status: Accepted

Solution code:
n = int(input())
als = list(map(int,input().split()))
ans = 'No'
sett = n//3
als.sort()
if als[0] == 0:
    if als[n-1] == 0:
        ans = 'Yes'
    else:
        cc = [0]*(n//2) + [als[n-1]]*(n//2)
        if cc == als:
            ans = 'Yes'
if n%3 == 0:
    co = [als[0]]*sett + [(als[0]^als[n-1])]*sett + [als[n-1]]*sett
    if co == als:
        ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
if not any(l):
  print("Yes")
elif n%3 != 0:
  print("No")
else:
  nx = n//3
  d = dict()
  for x in l:
    if x not in d:
      d[x] = 0
    d[x] += 1
  for x in d:
    if d[x] != nx and d[x] !=2*nx:
      print("No")
      break
  else:
    s = 0
    for x in d:
      if d[x] == nx:
        s ^= x
    if s == 0:
      print("Yes")
    else:
      print("No")

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = LI()

# 001, 101, 1000の場合など、最大桁数のものが1つしかない場合、絶対に1000と作る数は1XXXになるので、絶対無理
# 1000, 1001, 0101, 0001の場合、0001が作れる。しかし、1000はどう頑張っても作れない
# 全数字を2進数に直す結局全部1が並ぶやつ、つまり、1/1/0, 10/01/11, 111/100/011, 111/101/010などの組み合わせが必要
# そもそも3種類以上ある場合は絶対成り立たない
set_A = set(A)
if len(set_A) > 3:
    print('No')
    exit()

if len(set_A) == 1:
    if A[0] == 0:
        print('Yes')
    else:
        print('No')
elif len(set_A) == 2:
    # 2種類で成り立つのは、全部1111が2つと、全部000が1つの場合のみ
    A_list = list(set_A)
    if 0 in A_list:
        non_zero = [i for i in A_list if i != 0][0]
        if A_list[0] ^ A_list[1] == non_zero:
            # 0と1の比率が1:2でないとだめ。さらに、総数が3*2*n
            if A.count(0) * 2 == A.count(non_zero) and N % 3 == 0:
                # XORがA_listに入ってたら。
                print("Yes")
                exit()
            else:
                print('No')
                exit()
        else:
            print("No")
            exit()
    else:
        print('No')
        exit()
elif len(set_A) == 3:
    A_list = list(set_A)
    if A_list[0] ^ A_list[1] == A_list[2] and A_list[0] ^ A_list[2] == A_list[1] and A_list[1] ^ A_list[2] == A_list[0]:
        # それぞれの数が1:1:1でないとだめ
        if A.count(A_list[0]) == A.count(A_list[1]) == A.count(A_list[2]) and N % 3 == 0:
            print('Yes')
        else:
            print("No")
    else:
        print('No')

Submission status: Accepted

Solution code:
# 

n=int(input())
a=list(map(int,input().split()))
A=set(a[1:])
res=[-1]*n

dct={}
for e in a:
    dct[e]=dct.get(e,0)+1
tmp=a[0]
res[0]=tmp
dct[tmp]-=1

for i in range(1,n):
    tmp=res[0]^a[i]
    if  dct.get(tmp,0)>0:
        res[1]=a[i]
        res[-1]=res[0]^a[i]
        dct[res[1]]-=1
        dct[res[-1]]-=1
        break
else:
    print('No')
    exit()


for i in range(1,n-2):
    x=res[i]
    y=res[i-1]
    tmp=x^y
    if dct.get(tmp,0)>0:
        res[i+1]=tmp
        dct[tmp]-=1
    else:
        print('No')
        exit()

if res[-2]^res[-3]==res[-1]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
A.sort()
ONE=0
TWO=0
THREE=0
Ne=0
ZERO=0
AA=A[0]
BB=A[N//3]
CC=A[(N*2)//3]
AAA=bin(AA)
BBB=bin(BB)
CCC=bin(CC)
X=bin(AA^BB)
Y=bin(BB^CC)
Z=bin(CC^AA)
i=0
if A[0]==0:
    for x in range(0,N):
        if A[x]==0:
            ZERO=ZERO+1
        if A[x]==BB:
            Ne=Ne+1
    if ZERO==N:
        i=1
    if N%3==0 and ZERO==N//3 and Ne==(N*2)//3:
        i=1

if X==CCC and Y==AAA and Z==BBB:
    if N%3==0:
        for x in range(0,N):
            if AA==A[x]:
                ONE=ONE+1
            if BB==A[x]:
                TWO=TWO+1
            if CC==A[x]:
                THREE=THREE+1
        if ONE==TWO and TWO==THREE and THREE==N//3:
            i=1
if i==0:
    print("No")
if i==1:
    print("Yes")

Submission status: Accepted

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

nums = {}

for i in range(N):
    if A[i] in nums:
        nums[A[i]] += 1
    else:
        nums[A[i]] = 1

if len(nums) == 1:
    if '0' in nums:
        print('Yes')
    else:
        print('No')
elif len(nums) == 2:
    if '0' in nums and nums['0'] * 3 == len(A):
        print('Yes')
    else:
        print('No')
elif len(nums) == 3:
    keys = [x for x in nums]
    a = keys[0]
    b = keys[1]
    c = keys[2]
    if nums[a] == nums[b] and nums[a] == nums[c] and int(a) ^ int(b) == int(c) and int(b) ^ int(c) == int(a) and int(a) ^ int(c) == int(b):
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
A=list(map(int, input().split()))
x=A[0]
for i in range(1, N):
    x=int(bin(x ^ A[i]), 0)
    
if x==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

list0 = [0]*30
list1 = [0]*30

for mm in range(n):
    m = lista[mm]
    bin_str = format(m, '030b')
    #print(bin_str)

    for i in range(30):
        t = bin_str[i]
        if t == "1":
            list1[i] += 1
        else:
            list0[i] += 1

#print(list0)
#print(list1)

ans = "Yes"
for i in range(30):
    if list1[i]==0:
        continue
    
    num0 = list0[i]
    num1 = list1[i]
    if num0*2 != num1:
        ans = "No" 
        break
print(ans)

Submission status: Accepted

Solution code:
#!venv/bin/python
#from collections import defaultdict 
from itertools import combinations
import math
import datetime
N = int(input())
A = [int(x) for x in input().split()]

cnt = {}

kind = 0
for a in A:
    if not a in cnt:
        kind += 1
        cnt[a] = 0
    if kind > 3:
        break
    cnt[a] += 1

nums = list(cnt.keys())

if kind == 2:
    cnt0 = 0
    cnt_not0 = 0
    for n in [nums[0], nums[1]]:
        if n == 0:
            cnt0 += cnt[n]
        else:
            cnt_not0 = cnt[n]
    if cnt0 * 2 == cnt_not0:
        print("Yes")
    else:
        print("No")
elif kind == 3 and cnt[nums[0]] == cnt[nums[1]] == cnt[nums[2]] and nums[0] ^ nums[1] == nums[2]:
    print("Yes")
elif kind == 1 and nums[0] == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import defaultdict

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

if n == 3:
    if a[0] ^ a[2] == a[1] and a[1] ^ a[2] == a[0] and a[0] ^ a[1] == a[2]:
        print('Yes')
    else:
        print('No')
elif n % 3 == 0:
    d = defaultdict(int)
    for aa in a:
        d[aa] += 1
    m = n // 3
    bl = True
    t = []
    for k, v in d.items():
        if v % m != 0:
            bl = False
            break
        else:
            q = v // m
            t.append((k, q))

    if len(t) == 3:
        if t[0][0] ^ t[1][0] == t[2][0] and t[1][0] ^ t[2][0] == t[0][0] and t[2][0] ^ t[0][0] == t[1][0]:
            pass
        else:
            bl = False
    elif len(t) == 2:
        if t[0][1] > t[1][1]:
            if t[0][0] ^ t[0][0] == t[1][0] and t[0][0] ^ t[1][0] == t[0][0]:
                pass
            else:
                bl = False
        else:
            if t[1][0] ^ t[1][0] == t[0][0] and t[0][0] ^ t[1][0] == t[1][0]:
                pass
            else:
                bl = False


    elif len(t) == 1:
        if t[0][0] != 0:
            bl = False

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

else:
    if all(aa == 0 for aa in a):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
import collections

n=int(input())

a_list = list(map(int, input().split()))
#print(a_list)
c = collections.Counter(a_list)
#print(c)

values=list(c.values())
values.sort()
#print(values)

keys=list(c.keys())
keys.sort()
#print(keys)

ans="No"
if len(values)==3:
  if values[0]==values[1] and values[1]==values[2]:
    if keys[0] ^ keys[1]==keys[2]:
      ans="Yes"
  
if len(values)==2:
  if keys[0] == 0:
    if values[0]*2==values[1]:
      ans="Yes"

if len(values)==1:
  if keys[0] == 0:
      ans="Yes"

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin,stdout
n=int(stdin.readline())
l=map(int,stdin.readline().split())
ans=0
for i in l:
  ans^=i
if ans:
  stdout.write("No")
else:
  stdout.write("Yes")

Submission status: Accepted

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

A = sorted(A, reverse=True)
xor = A[0]
for a in A[1:]:
  xor ^= a 
if (xor == 0):
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

a.sort()
s = set(a)
if a[0] != 0:
    if (len(s) > 3) or (len(s) == 1) or (len(s) == 2):
        print('No')
        exit()

    l = [a[0]]
    c = []
    count = 1
    for i in range(n - 1):
        if a[i + 1] != a[i]:
            l.append(a[i + 1])
            c.append(count)
            count = 1
        else:
            count += 1
    c.append(count)

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

    c.sort()
    if c[0] != c[1] or c[1] != c[2]:
        print('No')
        exit()

    if (l[0] ^ l[1]) == l[2]:
        print('Yes')
        exit()
    print('No')
else:
    if len(s) == 1:
        print('Yes')
        exit()
    if len(s) > 3:
        print('No')
        exit()
    if len(s) == 3:
        print('No')
        exit()

    c = []
    count = 1
    for i in range(n - 1):
        if a[i + 1] != a[i]:
            c.append(count)
            count = 1
        else:
            count += 1
    c.append(count)

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

    if c[0] * 2 == c[1]:
        print('Yes')
        exit()
    print('No')
    exit()

Submission status: Accepted

Solution code:
def main(N):
	a = list(map(int, input().split()))
	if a.count(0) == N:
		print("Yes")
		return
	if N%3 != 0:
		print("No")
		return
	d={}
	for i in a:
		if i in d:
			d[i] = d[i] + 1
		else:
			d[i] = 1
	if 0 in d.keys():
		if d[0] == N//3:
			for i in d.keys():
				if i == 0:
					continue
				elif d[i] % 2 != 0:
					print("No")
					return
			print("Yes")
		else:
			print("No")
	else:
		for i in d.values():
			if i != N//3:
				print("No")
				return
		lst = list(d.keys())
		if (lst[0]^lst[2]!=lst[1]) or (lst[0] != lst[1]^lst[2]) or(lst[2]!=lst[1]^lst[0]):
			print("No")
			return
		print("Yes")
	return
		
	return

main(int(input()))

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
p = [0]*100000
for a in A:
    n = bin(a)[::-1]
    l = len(n)
    for i in range(l-1):
        if n[i]=='b':
            break
        if n[i] == '1':
            p[i] +=1
for a in p:
    if a%2==1:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
n=int(raw_input())
a=sorted(map(int, raw_input().split()))

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

Submission status: Accepted

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

st = set(a)
lst = list(st)

if n == 3 and a[0] ^ a[1] == a[2]:
  print("Yes")
elif n  >= 4 and st == {0}:
  print("Yes")
elif n % 3 == 0 and len(st) == 2 and a.count(0) == n /3:
  print("Yes")
elif n % 3 == 0 and len(st) == 3 and lst[0] ^ lst[1] == lst[2] and a.count(lst[0]) == n /3 and a.count(lst[1]) == n/3:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for i in a:
    d[i] += 1

if len(d) >= 4:
    print("No")
    exit()

if len(d) == 1:
    if 0 in d:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if len(d) == 2:
    if (N % 3) == 1 and 0 in d and d[0] == N // 3:
        print("Yes")
        exit()
    elif (N % 3) == 2 and 0 in d and d[0] == ((N // 3) + 1):
        print("Yes")
        exit()
    elif (N % 3) == 0 and 0 in d and d[0] == N // 3:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if len(d) == 3:
    l = list(d.values())
    l.sort()
    if l[0] == l[-1]:
        keys = list(d.keys())
        if keys[0] ^ keys[1] == keys[2]:
            print("Yes")
            exit()

print("No")

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for x in input().split():
    a = int(x)
    if a in d:
        d[a] += 1
    else:
        d[a] = 1
ans = "No"
if len(d) == 3 and len(set([d[key] for key in d]))== 1:
    a, b, c = d.keys()
    if a == b ^ c and b == a ^ c and c == b ^ a:
        ans = "Yes"
if len(d) == 2:
    a, b = sorted(list(d.keys()))
    if a == 0 and d[b] == 2 * d[a]:
        ans = "Yes"

if len(d) == 1:
    if list(d.keys())[0] == 0:
        ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
a = input()
b = input().split()
b = [int(i) for i in b]
b = sorted(b)

num = 0

for i in range(len(b)):
    num = num ^ b[i]


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

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    a = list(map(lambda x: int(x), input().split()))

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

    answer = "Yes" if res == 0 else "No"
    print(answer)

solve()

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=[int(_) for _ in input().split()]
c=collections.Counter(a)
l=len(c.keys())
k=list(c.keys())
v=list(c.values())
if l > 3:
    print("No")
elif l == 3:
    if k[0]^k[1]^k[2] == 0 and v[0]==v[1]==v[2] and n%3==0:
        print("Yes")
    else:
        print("No")
elif l == 2:
    if k[0] == 0:
        if v[1] == v[0]*2 and n%3==0:
            print("Yes")
        else:
            print("No")
    elif k[1] == 0:
        if v[0] == v[1]*2 and n%3==0:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif l == 1:
    if k[0] == 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

x = False
k = {}
for i in range(N):
    if not A[i] in k:
        k[A[i]] = 1
    else:
        k[A[i]] += 1
B = 0
a = 0
if len(k.keys()) == 3:
    B = 0
    for key, val in k.items():
        if val == N // 3:
            a += 1
        B = B ^ key
elif len(k.keys()) == 2:
    for key, val in k.items():
        if val == N // 3 and key == 0:
            a += 1
        elif val == N // 3 * 2:
            a += 2
    B = 0
elif len(k.keys()) == 1:
    a = list(k.keys())
    if a[0] == 0:
        x = True

if (N % 3 == 0 and B == 0 and a == 3) or x:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
import sys
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A

if __name__ == '__main__':
    N = int(input())
    A = InputToInt()
    if set(A) == {0}:
        print('Yes')
        sys.exit()
    
    if N%3 != 0:
        print('No')
        sys.exit()
    A.sort()

    n = int(N/3)
    if 1 == len(set(A[0:n])) and 1 == len(set(A[n:2*n])) and 1 == len(set(A[2*n:3*n])) and A[0] == A[n] ^ A[2*n]:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
if len(b)==1 and b[0]==0:
    print('Yes')
elif len(b)==2 and min(b)==0:
    b.sort()
    if n%3==0:
        if a.count(b[0])*2==a.count(b[1]):
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif n%3!=0:
    print('No')
else:
    if len(b)!=3:
        print('No')
    elif b[0]^b[1]==b[2]:
        if a.count(b[0])==a.count(b[1])==a.count(b[2]):
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

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

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

ok = False
counts = dict(Counter(A))
keys = counts.keys()
if len(counts) <= 3:
    for k1, k2, k3 in itertools.product(keys, repeat=3):
        cnt = counts.copy()
        s = k1
        cnt[k1] -= 1
        cnt[k2] -= 1
        if k1 ^ k2 != k3:
            continue
        n = 2
        while n < N:
            cnt[k3] -= 1
            k1, k2, k3 = k2, k3, k2 ^ k3
            n += 1
        if s == k3 and not any(cnt.values()):
            ok = True
            break

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

Submission status: Accepted

Solution code:
import collections
import sys

n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
value = list(c.values())
key = list(c.keys())

if 0 in key:
    if len(c) == 1 and key[0] == 0:
        print('Yes')
        sys.exit()
    elif len(c) == 2:
        for num, count in c.items():
            if num == 0:
                num0 = count
            else:
                numelse = count
        if num0 * 2 == numelse:
            print('Yes')
            sys.exit()
    else:
        print('No')
        sys.exit()

if len(c) != 3:
    print('No')
    sys.exit()

if value[0] != value[1] or value[1] != value[2] or value[2] != value[0]:
    print('No')
    sys.exit()

if key[0] ^ key[1] ^ key[2] != 0:
    print('No')
    sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
from collections import Counter

N= int(input())

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

x = Counter(a)

ok = False
if len(x) == 3 and len(a) % 3 == 0:
    for i in a:
        if x[i] != len(a) // 3:
            break
    else:
        w = 0
        for j in x:
            w ^= j
        if w == 0:
            ok = True
elif len(x) == 1:
    if x.get(0) is not None:
        ok = True
elif len(x) == 2 and len(a) % 3 == 0:
    if x.get(0) is not None and x[0] == len(a) // 3:
        ok = True

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

Submission status: Accepted

Solution code:
import numpy as np

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

a = np.array(a)




def make_Xor(a,b):
	d_ = []
	for i in range(len(a)):
		if a[i] == b[i]:
			d_.append("0")
		else:
			d_.append("1")
	return d_


def judge_of_3(a):
	a_ = []
	a_.append(list(format(a[0],'b')))
	a_.append(list(format(a[1],'b')))
	a_.append(list(format(a[2],'b')))
	max_len = max(len(a_[0]),len(a_[1]),len(a_[2]))
	for i in range(3):
		while len(a_[i]) < max_len:
			a_[i].insert(0,'0')
	if make_Xor(a_[0],a_[1]) == a_[2]:
		return True
	else:
		return False
	
	
judge = True

if N % 3 == 0:
	a_1 = np.unique(a)
	if len(a_1) <= 3:
		a = list(a)
		a.sort()
		div_3 = N // 3
		for i in range(3):
			if a[i * div_3] != a[(i+1) * div_3 - 1]:
				judge = False
		a_1 = [a[0],a[div_3],a[2*div_3]]
		if judge:
			if judge_of_3(a_1):
				judge = True
			else:
				judge = False
	else:
		judge = False
else:
	a_1 = np.unique(a)
	a_1 = list(a_1)
	if len(a_1) != 1:
		judge = False
	if a_1[0] != 0:
		judge = False

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

Submission status: Accepted

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

is_yes = False

a_n_unique = list(set(a_n))

if len(a_n_unique) == 1:
    if a_n_unique[0] == 0:
        is_yes = True

elif N % 3 == 0:
    if len(a_n_unique) == 2:
        if a_n_unique[0] == 0 or a_n_unique[1] == 0:
            if a_n.count(a_n_unique[0]) > a_n.count(a_n_unique[1]):
                if a_n.count(a_n_unique[0]) / a_n.count(a_n_unique[1]) ==2:
                    is_yes = True
            else:
                if a_n.count(a_n_unique[1]) / a_n.count(a_n_unique[0]) ==2:
                    is_yes = True
    elif len(a_n_unique) == 3:
        if a_n_unique[0] ^ a_n_unique[1] == a_n_unique[2]:
            if a_n.count(a_n_unique[0]) == a_n.count(a_n_unique[1]) and a_n.count(a_n_unique[0]) == a_n.count(a_n_unique[2]):
                is_yes = True


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

Submission status: Accepted

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

import collections
c = collections.Counter(a)
unique = list(set(a))

from operator import xor
v = []
for k in c.keys():
    v.append(c[k])
v.sort()

flag = False
if n % 3 == 0:
    if len(v) == 1:
        if v == [n] and unique[0] == 0:
            flag = True
    elif len(v) == 2:
        if v == [n // 3, n // 3 * 2]:
            if c[unique[0]] == n // 3:
                if xor(unique[1], unique[0]) == unique[1] and xor(unique[1], unique[1]) == unique[0]:
                    flag = True
            else:
                if xor(unique[0], unique[1]) == unique[0] and xor(unique[0], unique[0]) == unique[1]:
                    flag = True
    elif len(v) == 3:
        if v == [n // 3, n // 3, n // 3]:
            if xor(unique[0], unique[1]) == unique[2] and xor(unique[1], unique[2]) == unique[0] and xor(unique[2], unique[0]) == unique[1]:
                flag = True
else:
    if v == [n]:
        flag = True

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

Submission status: Accepted

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

if n % 3 != 0:
    if all(map(lambda x: x == 0, aa)):
        print('Yes')
    else:
        print('No')
else:
    m = n // 3

    cnt_map = {}
    for a in aa:
        if a not in cnt_map:
            cnt_map[a] = 0
        cnt_map[a] += 1

    if len(cnt_map.keys()) > 3:
        print('No')
    elif len(cnt_map.keys()) == 1:
        k = list(cnt_map.keys())[0]
        if k == 0:
            print('Yes')
        else:
            print('No')
    elif len(cnt_map.keys()) == 2:
        k1, k2 = cnt_map.keys()
        if k1 > k2:
            k1, k2 = k2, k1
        if k1 == 0 and cnt_map[k1] == m:
            print('Yes')
        else:
            print('No')
    elif len(cnt_map.keys()) == 3:
        a, b, c = cnt_map.keys()
        if a == b ^ c and cnt_map[a] == m and cnt_map[b] == m and cnt_map[c] == m:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
a = int(input())
x = list(map(int,input().split()))
ax = list(set(x))
x.sort()
ax = list(set(x))
def ch(l):
    # print(l,l[1:] + [l[0]], l[2:] + [l[0]] +[l [1]])
    for i, j ,k in zip(l,l[1:] + [l[0]], l[2:] + [l[0]] +[l [1]]):
        if j != i ^ k: break
    else:
        return(1)
    return(0)
def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a==t : print('Yes')
    else : print('No')
if len(ax) < 3:
    if (sum(x) == 0) :
        print("Yes")
        exit()
    if (len(ax)) <2:
        print("No")
        exit()
    if x.count(0)*2 == x.count(ax[1]) and len(x) == x.count(0) + x.count(ax[1]):
        print("Yes")
        exit()
        
    print("No")
    exit()
t = (len(x) == x.count(ax[0]) + x.count(ax[1]) + x.count(ax[2])) * (x.count(ax[1]) == x.count(ax[0]) and x.count(ax[0]) == x.count(ax[2]))*ch(ax)

y(1,t)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    a = [int(x) for x in input().split()]
    n0 = a.count(0)
    b = [x for x in a if x!=0]
    ans = 'No'
    if n0==N:
        ans = 'Yes'
    elif n0 != 0 and a.count(b[0])==n0*2 and N==n0*3:
        ans = 'Yes'
    elif len(set(b))==3:
        b1,b2,b3 = list(set(b))
        n1 = b.count(b1)
        n2 = b.count(b2)
        n3 = b.count(b3)
        if b1^b2==b3 and n1==n2==n3:ans = 'Yes'
    print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
from operator import itemgetter

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

ans = "Yes"
L = []
L_cnt = {}
for a in A:
    if a in L:
        L_cnt[a]+=1
        continue

    if len(L)>=3:
        ans = "No"
        break
    L.append(a)
    L_cnt[a]=1

if len(L)==3:
    l1, l2, l3 = L
    if N%3!=0:
        ans="No"
    if not L_cnt[l1]==L_cnt[l2]==L_cnt[l3]:
        ans="No"
    while ans=="Yes":
        sumL = l1%2 + l2%2 + l3%2
        if sumL!=0 and sumL!=2:
            ans = "No"
            break
        l1 = l1//2
        l2 = l2//2
        l3 = l3//2
        if l1+l2+l3==0:
            break
    print(ans)
elif len(L)==2:
    if N%3!=0:
        ans="No"
    if L_cnt[0]!=N//3:
        ans="No"
    if L[0]!=0 and L[1]!=0:
        ans="No"
    print(ans)
else:
    if sum(L)!=0:
        ans="No"
    print(ans)