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:
def resolve():
    n = int(input())
    dataset = list(map(int, input().split()))

    xor = 0

    for i in range(n):
        xor ^= dataset[i]

    if xor == 0:
        print('Yes')
    else:
        print('No')
        
resolve()

Submission status: Accepted

Solution code:


def main():
    num = int(input())
    data = list(map(int, input().split()))

    ans = 0
    for i in range(num):
        ans ^= data[i]

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



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = input()
s = list(map(int, input().split()))
a = 0
for x in s:
  a ^= x
if a==0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
setA = set(A)
if len(setA) == 3:
    a, b, c = list(setA)
    print('Yes' if a ^ b ^ c == 0 and A.count(a) == A.count(b) == A.count(c) else 'No')
elif len(setA) == 2: print('Yes' if 2*A.count(0) == A.count(max(setA)) else 'No')
elif len(setA) == 1: print('Yes' if max(setA) == 0 else 'No')
else: print('No')

Submission status: Accepted

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

if all(i == 0 for i in a):
    print('Yes')
    exit()

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

if 0 in a:
    a = sorted(a)
    zero = a.count(0)
    if zero != p:
        print('No')
        exit()
    if a[p] != a[-1]:
        print('No')
        exit()
    print('Yes')
    exit()

a = sorted(a)
if a.count(a[0]) != p or a.count(a[p]) != p or a.count(a[-1]) != p:
    print('No')
else:
    if a[0] ^ a[p] == a[-1]:
	    print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    n, = read_h()
    arr = read_h()
    #  print(arr)

    s = 0
    for a in arr:
        s ^= a

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import copy
N=int(input())
a_list=list(map(int,input().split()))
a=set(a_list)
a=list(a)
if 0 in a:
        if len(a) ==2:
            if a_list.count(0)==len(a_list)//3 or a_list.count(0)==len(a_list)//2:
                    print("Yes")
            else:
                    print("No")
        elif len(a)==1:
            print("Yes")
        else:
                print("No")
else:
        if len(a)==3:
            a1=a[0]
            a2=a[1]
            a3=a[2]
            if a1 ^ a2 ==a3 and a1^a3==a2 and a2^a3==a1:
                if a_list.count(a1) == a_list.count(a2) == a_list.count(a3):
                        print("Yes")
                else:
                        print("No")
            else:
                print("No")
        else:
            print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
from collections import Counter
def main():
    N = int( input())
    A = list( map( int, input().split()))
    CA = Counter(A)
    d = dict()
    if len(CA) > 3:
        print("No")
        return
    if len(CA) == 1:
        if CA[0] == N:
            print("Yes")
            return
        else:
            print("No")
            return
    if len(CA) == 2:
        for c in CA:
            if c != 0:
                t = c
        if N%3 == 0 and CA[t]== CA[0]*2:
            print("Yes")
        else:
            print("No")
        return
    ans = "Yes"
    s = 0
    for c in CA:
        s ^= c
        if CA[c] != N//3:
            ans = "No"
    if s != 0:
        ans = "No"
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  a[i]=format(a[i],'030b')
l=[0 for i in range(30)]
for i in range(n):
  for j in range(30):
    if a[i][j]=='1':
      l[j]+=1
for j in range(30):
  l[j]=l[j]%2
 
if 1 in l:
  print('No')
else:
  print('Yes')

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a)
x = sorted(c.keys())

# aに4種類以上異なる値が存在する場合、No
ans = (
    'Yes' if (
        len(x) == 3 and x[0] ^ x[1] == x[2] and
        c[x[0]] == c[x[1]] == c[x[2]] or
        len(x) == 2 and x[0] == 0 and c[x[1]] == 2 * c[0] or
        len(x) == 1 and x[0] == 0
    ) else
    'No'
)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
al=list(map(int,input().split()))
t=0
for a in al:
    t^=a
print('Yes' if t==0 else 'No')

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
flag = True
if len(set(a)) == 1 and a[0] == 0:
    #print('Yes')
    pass
elif N % 3 == 0:
    if len(set(a)) == 3:
        b = list(set(a))
        c = []
        for i in b:
            c.append(a.count(i))
        if a[0] != 0 and c[0] == c[1] and  c[1] == c[2] and c[2] == N//3 and b[0]^b[1]^b[2] == 0:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) and a.count(a[N-1]) == N//3*2:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    else:
        #print('No')
        flag = False
else:
    #print('No')
    flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# 1.Nが三の倍数でない場合、全てが0でなければならない.(a_i=Σa_k∧a_(i-1)+a_(i+1)=a_iとなるのはa_i=0のみ)
# 2.Nが3の倍数の場合、a,b,a+bを満たす三種類以下の数字で構成されていなければならず、かつそれであればよい。

N = int(input())
string = "No"
input_dict = {}
for i in map(int, input().split()):
    if(i in input_dict):
        input_dict[i] += 1
    else:
        input_dict[i] = 1
if((N % 3) == 0):
    num_count = len(input_dict.keys())
    if(num_count == 3 ):
        input_list = list(input_dict.keys())
        if(input_list[0] ^ input_list[1] == input_list[2] and input_dict[input_list[0]] == N//3 and input_dict[input_list[1]] == N//3):
            string = "Yes"
    elif(num_count == 2):
        if(0 in input_dict and input_dict[0] == N//3):
            string = "Yes"
    elif(num_count == 1):
        if(0 in input_dict):
            string = "Yes"
else:
    if(0 in input_dict and input_dict[0] == N):
        string = "Yes"
print(string)

Submission status: Accepted

Solution code:
import collections 

def is_loop(int_list):
    counter = collections.Counter(input_list)

    unique_list = list(counter.keys())
    counts = list(counter.values())

    if (all(num == 0 for num in unique_list)):
        return True
    else:
        if n % 3 == 0:
            zero_count = counter[0] 
            if zero_count == n / 3 and len(unique_list) == 2:
                return True
            else: 
                if len(unique_list) != 3:
                    return False
                if (unique_list[0] ^ unique_list[1] == unique_list[2]):
                    if (all(counts[0] == num for num in counts)):
                        return True
    return False

n = int(input())
input_list = [int(i) for i in input().split(' ')]
if is_loop(input_list):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a = [input() for i in range(2)]
 
N = int(a[0])
data = a[1].split(' ')
 
data = [int(i) for i in data]
 
result = []
a = 0
for i in range(N):
    a = a ^ data[i]
    
if a == 0:
    print('Yes')
    exit()
    
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) == 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:
def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    A = sorted(A)
    xor_a = 0
    
    if max(A) == 0:
        return 1
    if N % 3 == 0:
        if A[0] == 0:
            for i in range(N//3):
                if A[i] != 0:
                    return 0
            for i in range(N//3, N):
                if A[i] != A[N//3]:
                    return 0
            return 1
        else:
            for i in range(N//3):
                if A[i] != A[0]:
                    return 0
            for i in range(N // 3, 2 * N // 3):
                if A[i] != A[N // 3]:
                    return 0
            for i in range(2 * N // 3, N):
                if A[i] != A[2 * N // 3]:
                    return 0
            for i in range(N):
                xor_a ^= A[i]
            return 1 if xor_a == 0 else 0
    else:
        return 0


if __name__ == '__main__':
    inputs = read()
    print('Yes' if solve(*inputs) else 'No')

Submission status: Accepted

Solution code:
import collections

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

value, count = list(a.keys()), list(a.values())

if len(value)<3:
    if len(value)==1:
        if sum(a)==0:
            print('Yes')
        else:
            print('No')

    if len(value)==2:
        if 0 in value:
            if count[0]==N/3 or count[1]==N/3:
                print('Yes')
            else:
                print('No')

        else:
            print('No')

if len(value)>=3:
    if count[0]+count[1]+count[2] == N:
        if value[0]^value[1]^value[2] == 0:
            if count[0]==count[1]==count[2]:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')

Submission status: Accepted

Solution code:
import sys
inputs = sys.stdin.readlines()

N = int(inputs[0])
a_list = list(map(int, inputs[1].split()))

from collections import Counter

def all_zeros(a_list):
    return sum(a_list) == 0

def check(N, a_list):
    if all_zeros(a_list):
        print('Yes')
        return
    elif N % 3 == 0:
        x = N // 3
        if not all([v % x == 0 for v in Counter(a_list).values()]):
            print('No')
            return
        while not all_zeros(a_list):
            counter = Counter([a & 1 for a in a_list])
            if counter[0] == x or counter[0] == N:
                a_list = [a >> 1 for a in a_list]
            else:
                print('No')
                return
        print('Yes')
    else:
        print('No')

check(N, a_list)

Submission status: Accepted

Solution code:
from collections import Counter

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

if len(o) >=4:
    print('No')
    exit()
if len(o) == 3:
    if o[0][1]==o[1][1] and o[1][1] == o[2][1]:
        if o[0][0]^o[1][0] == o[2][0] and o[1][0]^o[2][0] == o[0][0] and o[2][0]^o[0][0] == o[1][0]:
            print('Yes')
            exit()
    print('No')
    exit()
if len(o) == 2:
    if n%3 == 0:
        if o[1][0] == 0 and o[1][1] == n//3:
            print('Yes')
            exit()
    print('No')
    exit()

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

Submission status: Accepted

Solution code:
from collections import Counter

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

def solve():
    C = Counter(A)
    M = len(C)
    if M == 1 and 0 in C:
        return True
    elif M == 2:
        if 0 in C:
            b = 0
            for k, v in C.items():
                if k != 0:
                    b = v
            a = C[0]
            return (b == a * 2)
        else:
            return False
    elif M == 3:
        a, b, c = C.keys()
        if a ^ b == c or b ^ c == a or c ^ a == b:
            return (C[a] == C[b] == C[c])
        else:
            return False
    else:
        return False

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

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
setA = set(A)
if len(setA) == 3:
    a, b, c = list(setA)
    if a ^ c == b and a ^ b == c and b ^ c == a and A.count(a) == A.count(b) == A.count(c): print('Yes')
    else: print('No')
elif len(setA) <= 2:
    maxA = max(setA)
    if A.count(0) == A.count(maxA) or 2*A.count(0) == A.count(maxA): print('Yes')
    else: print('No')
else: print('No')

Submission status: Accepted

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


rtn = "Yes"

t = 0

for i,ai in enumerate(a):
    t ^= ai

if (t != 0):
    rtn = "No"

print(rtn)

Submission status: Accepted

Solution code:
n = int(input())
c = list(map(int, input().split()))
c.sort()
c_set = set(c)
set_list = list(c_set)
ans = 'No'

# 0が混ざっていれば計算方法が違う
if c.count(0) == n:
    ans = 'Yes'
elif c[0] == 0:
    if n % 3 == 0 and len(c_set) == 2 and c.count(0) == int(n / 3):
        ans = 'Yes'
elif n == 3:
    if c[0] ^ c[1] == c[2]:
        ans = 'Yes'
else:
    if n % 3 == 0 and len(c_set) == 3:
        ank = int(n / 3)
        if c.count(c[0]) == ank and c.count(c[ank]) == ank and set_list[0] ^ set_list[1] == set_list[2]:
            ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
import collections


N = int(input())
a = list(map(int, input().split()))
C = collections.Counter(a)
L = len(C)
e = list(C.keys())
print(
    (
        ((L == 1) and (C[0] > 0))
        or ((L == 2) and (C[0] > 0) and (C[e[0]] * 2 == C[e[1]]))
        or ((L == 3) and (C[e[0]] == C[e[1]] == C[e[2]]) and ((e[0] ^ e[1]) == e[2]))
    )
    and "Yes"
    or "No"
)

Submission status: Accepted

Solution code:
import collections 

n = int(input())
input_list = [int(i) for i in input().split(' ')]

counter = collections.Counter(input_list)


unique_list = list(counter.keys())
counts = list(counter.values())

if (all(num == 0 for num in unique_list)):
    print('Yes')
else:
    if n % 3 == 0:
        zero_count = counter[0] 
        if zero_count == n / 3 and len(unique_list) == 2:
            print('Yes')
        else: 
            if len(unique_list) != 3:
                print('No')
            elif (unique_list[0] ^ unique_list[1] == unique_list[2]):
                if (all(counts[0] == num for num in counts)):
                    print('Yes')
                else:
                    print('No')
            else:
                print('No')
    else:
        print('No')

Submission status: Accepted

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

Submission status: Accepted

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

sums = 0
for i in range(N):
    sums ^= a[i]

f = True
for i in range(N):
    if a[i] == sums ^ a[i]:
        pass
    else:
        f = False

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

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = inp()
aa = inpl()
aa.sort()

def product():
    if N%3 == 0:
        ax = aa[0:N//3]
        bx = aa[N//3:N//3*2]
        cx = aa[N//3*2:]
        if len(set(ax)) != 1:
            return 'No'
        if len(set(bx)) != 1:
            return 'No'
        if len(set(cx)) != 1:
            return 'No'
        if ax[0]^bx[0] != cx[0]:
            return 'No'
        if bx[0]^cx[0] != ax[0]:
            return 'No'
        if cx[0]^ax[0] != bx[0]:
            return 'No'
        return 'Yes'

    else:
        for a in aa:
            if a != aa[0]:
                return 'No'
        return 'Yes'



print(product())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
m=int(input())//3;a=sorted(map(int,input().split()));print('YNeos'[(a[0],a[m],a[-m])!=(a[m-1],a[-m-1],a[-1])or a[0]^a[m]!=a[-m]::2])

Submission status: Accepted

Solution code:
import collections


N = int(input())
a = list(map(int, input().split()))
C = collections.Counter(a)
L = len(C)
e = list(C.keys())
if (L == 1) and (C[0] > 0):
    print("Yes")
elif (L == 2) and (C[0] > 0) and (C[e[0]] * 2 == C[e[1]]):
    print("Yes")
elif (L == 3) and (C[e[0]] == C[e[1]] == C[e[2]]) and ((e[0] ^ e[1]) == e[2]):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
#入力
#a = int(input())
#b,c = map(int, input().split())
#s = input()

N = int(input())
s = input()
a = np.asarray(s.split(), dtype=int)

#処理

d = {}
for val  in a:
    if val in d.keys():
        d[val] += 1
    else:
        d[val] = 1

keyNum = len(d.keys())
num = len(a)
keys = list(d.keys())

#条件１
if len(d.keys()) == 1 and 0 in d.keys():
    print ("Yes")
elif len(a) % 3 != 0:
    print ("No")
elif keyNum == 2:
    keys.sort()
    if keys[0] != 0:
        print ("No")
    elif d[0] != num//3:
        print ("No")
    else:
        print ("Yes")
#        keys1 = format(keys[1],'b')
#        isAll1 = True
#        for x in keys1:
#            if x != '1':
#                isAll1 = False
#                break
#        if isAll1:
#            print ("Yes")
#        else:
#            print ("No")

elif keyNum != 3:
    print ("No")

else:
    if d[keys[0]] != num//3:
        print ("No")
    elif d[keys[1]] != num//3:
        print ("No")
    elif d[keys[2]] != num//3:
        print ("No")
    else:
        key1 = format(keys[0],'099b')
        key2 = format(keys[1],'099b')
        key3 = format(keys[2],'099b')
        isA = True
        for k1,k2,k3 in zip(key1,key2,key3):
            kk1 = int(k1)
            kk2 = int(k2)
            kk3 = int(k3)
            goukei = kk1 + kk2 + kk3
            if not (goukei == 0 or goukei == 2):
                isA = False
                break
        
        if isA:
            print ("Yes")
        else:
            print ("No")

Submission status: Accepted

Solution code:
m=int(input())//3
a=sorted(map(int,input().split()))
print('YNeos'[(a[0],a[m],a[-m])!=(a[m-1],a[-m-1],a[-1]) or a[0]^a[m]!=a[-m]::2])

Submission status: Accepted

Solution code:
import sys,itertools,copy
input = sys.stdin.readline
N=int(input().strip())
an=[int(x) for x in input().strip().split()]

if N==3:
    if an[0]^an[1]==an[2]:
        print("Yes")
    else:
        print("No")
elif N%3!=0:
    if len(set(an))==1:
        print("Yes")
    else:
        print("No")
else:
    bn = list(set(an))
    if len(bn)>3:
        print("No")
    elif len(bn)==1:
        if bn[0]==0:
            print("Yes")
        else:
            print("No")
    elif len(bn)==2:
        if an.count(0)==(N/3):
            print("Yes")
        else:
            print("No")
    elif bn[0]^bn[1]!=bn[2]:
        print("No")
    else:
        for b in bn:
            if an.count(b)!=(N/3):
                print("No")
                break
        else:
            print("Yes")

Submission status: Accepted

Solution code:
a=int(input())
b=list(map(int, input().split()))
c=list(set(b))
t=0
d=[0 for i in range(len(c))]
if a==1:
  print("Yes")
else:
  if len(c)==1:
    if c[0]==0:
      print("Yes")
    else:
      print("No")
  elif len(c)==2:
    for i in range(len(c)):
      e=c[i]
      d[i]=b.count(e)
    if (c[0]==0 and d[0]*2==d[1])or (c[1]==0 and d[1]*2==d[0]):
      print("Yes")
    else:
      print("No")
  elif len(c)>3:
    print("No")
  else:  
    for i in range(len(c)):
      e=c[i]
      d[i]=b.count(e)
    if d[0]==d[1]and d[0]==d[2] and c[0]==c[1]^c[2]:
      print("Yes")
    else:
      print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(map(int,input().split()))
m=n//3
print('YNeos'[(a[0],a[m],a[-m])!=(a[m-1],a[-m-1],a[-1]) or a[0]^a[m]!=a[-m]::2])

Submission status: Accepted

Solution code:
from sys import stdin
from collections import defaultdict
def main():
    n = int(stdin.readline())
    a = map(int, stdin.readline().split())
    d = defaultdict(int)
    for x in a:
        d[x] += 1
    s = d.keys()
    if len(s) == 1:
        print 'Yes' if s[0] == 0 else 'No'
    elif len(s) == 2:
        print 'Yes' if (0 in s and (d[s[0]] == d[s[1]] or n % 3 == 0 and d[0] == n / 3)) else 'No'
    elif len(s) == 3:
        print 'Yes' if (s[0] ^ s[1] ^ s[2] == 0 and d[s[0]] == d[s[1]] == d[s[2]]) else 'No'
    else:
        print 'No'
main()

Submission status: Accepted

Solution code:
from collections import Counter
from functools import reduce

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

count = Counter((a))
len_count = len(count)

if len_count >= 4:
    print("No")
elif len_count == 1:
    if a[0] == 0:
        print("Yes")
    else:
        print("No")
elif len_count == 3:
    count_count = Counter(count.values())
    if len(count_count) == 1 and reduce(lambda x, y: x ^ y, count.keys()) == 0:
        print("Yes")
    else:
        print("No")
else:
    if count[0] * 3 == len(a):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
ans = "No"
Co = Counter(A)
if n % 3 != 0 : #3の倍数でない
    if len(Co.keys()) == 1 and list(Co.keys())[0] == 0:
        ans = "Yes" #要素の種類は1つかつその要素は0の場合のみOK
else :
    tr = n // 3
    Va = Co.values()
    if len(Va) == 3 :
        if Co.most_common()[0][1] == Co.most_common()[1][1] == Co.most_common()[2][1] == tr:
            a,b,c = Co.most_common()[0][0],Co.most_common()[1][0],Co.most_common()[2][0]
            if a^b==c and b^c==a and c^a==b:
                ans = "Yes"
    elif len(Va) == 2 and Co.most_common()[0][1] == 2 * tr :
        a, b = Co.most_common()[0][0], Co.most_common()[1][0]
        if a^b==a and a^a==b:
            ans = "Yes"
    elif len(Va) == 1 and Co.most_common()[0][0] == 0 :
        ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
import collections

N = int(input())
a = list(map(int, input().split()))
C = collections.Counter(a)
L = len(C)
e = list(C.keys())
if (L == 1) and (C[0] > 0):
    print("Yes")
elif (L == 2) and (C[e[0]] * 2 == C[e[1]]):
    print(((e[0] ^ e[0] == e[1]) or (e[1] ^ e[1] == e[0])) and "Yes" or "No")
elif (L == 3) and (C[e[0]] == C[e[1]]) and (C[e[1]] == C[e[2]]):
    print(((e[0] ^ e[1]) == e[2]) and "Yes" or "No")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(A)
K = c.keys()

ans = "No"
if len(K)==3:
    B = []
    for k in K:
        B.append(k)
    if c[B[0]]==c[B[1]] and c[B[1]]==c[B[2]] and B[0]^B[1]==B[2]:
        ans = "Yes"
elif len(K)==2:
    B = []
    for k in K:
        B.append(k)
    if (c[B[0]]==2*c[B[1]] or c[B[1]]==2*c[B[0]]) and (B[0]==0 or B[1]==0):
        ans = "Yes"
elif sum(A)==0:
    ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
aa=set(a)
if len(aa)>3:
    print("No")
    exit()
elif a.count(0)==n:
    print("Yes")
    exit()
elif len(aa)<=1:
    print("No")
    exit()
l=[]
l.append(a[0])
for i in range(1,n):
    if a[i]!=a[0]:
        l.append(a[i])
        break
l.append(l[0]^l[1])

if n==0:
    exit()
else:
    if len(aa)==2:
        if n%3==0:
            if (a.count(l[0])==(n//3)*2 and a.count(l[1])==n//3) or (a.count(l[1])==(n//3)*2 and a.count(l[0])==n//3):
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if (a.count(l[0])==(n//3)*2+1 and a.count(l[1])==n//3) or (a.count(l[1])==(n//3)*2 and a.count(l[0])==n//3+1):
                print("Yes")
            else:
                print("No")
        elif n%3==2:
            if (a.count(l[0])==(n//3)*2+1 and a.count(l[1])==n//3+1) or (a.count(l[1])==(n//3)*2+1 and a.count(l[0])==n//3+1):
                print("Yes")
            else:
                print("No")


    else:
        if n%3==0:
            if a.count(l[0])==n//3 and a.count(l[1])==n//3 and a.count(l[2])==n//3:
                print("Yes")
            else:
                print("No")
        else:
            print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=sorted([int(i) for i in input().split()])
m=n//3
print('YNeos'[(a[0],a[m],a[-m])!=(a[m-1],a[-m-1],a[-1]) or a[0]^a[m]!=a[-m]::2])

Submission status: Accepted

Solution code:
import collections

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

C = collections.Counter(a)
L = len(C)
e = list(C.keys())
if (L == 1) and (C[0] > 0):
    print("Yes")
elif (L == 2) and (C[e[0]] * 2 == C[e[1]]):
    print(((e[0] ^ e[0] == e[1]) or (e[1] ^ e[1] == e[0])) and "Yes" or "No")
elif (L == 3) and (C[e[0]] == C[e[1]]) and (C[e[1]] == C[e[2]]):
    print(((e[0] ^ e[1]) == e[2]) and "Yes" or "No")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np

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

for a in arr:
    if a not in d:
        d[a] = 1
    else:
        d[a] += 1


if len(d) == 1:
    if 0 in d:
        print("Yes")
    else:
        print("No")
elif len(d) == 2:
    if n%3 != 0:
        print("No")
    elif 0 in d:
        flag = True
        for key in d.keys():
            if key == 0:
                if not d[key] == n//3:
                    flag = False
            else:
                if not d[key] == 2*n//3:
                    flag=False
        if flag:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

elif len(d) != 3:
    print("No")

else:
    if n % 3 != 0:
        print("No")
    elif 0 in d:
        print("No")
    else:
        tartar = [0,0,0]
        num = [0,0,0]
        temp = 0
        for key in d.keys():
            tartar[temp] = key
            num[temp] = d[key]
            temp+=1
        if not (num[0] == num[1] and num[1] == num[2]):
            print("No")
        else:
            tar2 = [
                [tartar[0], tartar[1], tartar[2]],
                [tartar[0], tartar[2], tartar[1]],
                [tartar[1], tartar[0], tartar[2]],
                [tartar[1], tartar[2], tartar[0]],
                [tartar[2], tartar[1], tartar[0]],
                [tartar[2], tartar[0], tartar[1]],

            ]
            flag = False
            for tar in tar2:
                x1 = tar[0]^tar[2]
                x2 = tar[0]^tar[1]
                x3 = tar[1]^tar[2]

                if x1 == tar[1] and x2 == tar[2] and x3 == tar[0]:
                    flag = True
            if flag:
                print("Yes")
            else:
                print("No")

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
flag = True
syugo = set(sorted(data))
if len(syugo) == 1:
    syugo = list(syugo)
    if syugo[0] != 0:
        flag = False

elif len(syugo) == 2:
    syugo = list(syugo)
    if syugo[0] != 0:
        flag = False
    if data.count(syugo[1]) != data.count(0)*2:
        flag = False
        
elif len(set(data)) == 3:
    syugo = list(syugo)
    if syugo[0]^syugo[1] != syugo[2]:
        flag = False
    if len(set([data.count(i) for i in syugo])) != 1:
        flag = False
else:
    flag = False

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